about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/bits/socket.h
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/bits/socket.h')
-rw-r--r--sysdeps/unix/sysv/linux/bits/socket.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 226e332043..a11c22db72 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -204,18 +204,19 @@ extern struct cmsghdr *__cmsg_nxthdr __P ((struct msghdr *__mhdr,
 _EXTERN_INLINE struct cmsghdr *
 __cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg)
 {
-  unsigned char *__p;
-
   if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
     /* The kernel header does this so there may be a reason.  */
     return NULL;
 
-  __p = (((unsigned char *) __cmsg)
-	 + ((__cmsg->cmsg_len + sizeof (long int) - 1) & ~sizeof (long int)));
-  if (__p >= (unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)
+  __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
+			       + CMSG_ALIGN (__cmsg->cmsg_len));
+  if ((unsigned char *) (__cmsg + 1) >= ((unsigned char *) __mhdr->msg_control
+					 + __mhdr->msg_controllen)
+      || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
+	  >= ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
     /* No more entries.  */
     return NULL;
-  return (struct cmsghdr *) __p;
+  return __cmsg;
 }
 
 /* Socket level message types.  This must match the definitions in