Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys fix alignment problem in ancillary messages (alpha).



details:   https://anonhg.NetBSD.org/src/rev/02638875a8a4
branches:  trunk
changeset: 482641:02638875a8a4
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Feb 18 05:19:23 2000 +0000

description:
fix alignment problem in ancillary messages (alpha).

the change constitutes binary compatibility issue hen sizeof(long) !=4.
there's no way to be backward compatible, and only guys affected
are IPv6 userland tools.

From: =?iso-8859-1?Q?G=F6ran_Bengtson?= <goeran%cdg.chalmers.se@localhost>

diffstat:

 sys/kern/uipc_socket2.c |   8 ++++----
 sys/sys/socket.h        |  10 ++++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diffs (68 lines):

diff -r cd9d125fe961 -r 02638875a8a4 sys/kern/uipc_socket2.c
--- a/sys/kern/uipc_socket2.c   Fri Feb 18 04:16:54 2000 +0000
+++ b/sys/kern/uipc_socket2.c   Fri Feb 18 05:19:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket2.c,v 1.33 1999/08/04 22:33:20 mycroft Exp $        */
+/*     $NetBSD: uipc_socket2.c,v 1.34 2000/02/18 05:19:23 itojun Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1990, 1993
@@ -800,14 +800,14 @@
        register struct cmsghdr *cp;
        struct mbuf *m;
 
-       if (size + sizeof(*cp) > MCLBYTES) {
+       if (CMSG_LEN(size) > MCLBYTES) {
                printf("sbcreatecontrol: message too large %d\n", size);
                return NULL;
        }
 
        if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
                return ((struct mbuf *) NULL);
-       if (size + sizeof(*cp) > MLEN) {
+       if (CMSG_LEN(size) > MLEN) {
                MCLGET(m, M_DONTWAIT);
                if ((m->m_flags & M_EXT) == 0) {
                        m_free(m);
@@ -816,7 +816,7 @@
        }
        cp = mtod(m, struct cmsghdr *);
        memcpy(CMSG_DATA(cp), p, size);
-       size += sizeof(*cp);
+       size = CMSG_LEN(size);
        m->m_len = size;
        cp->cmsg_len = size;
        cp->cmsg_level = level;
diff -r cd9d125fe961 -r 02638875a8a4 sys/sys/socket.h
--- a/sys/sys/socket.h  Fri Feb 18 04:16:54 2000 +0000
+++ b/sys/sys/socket.h  Fri Feb 18 05:19:23 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: socket.h,v 1.49 2000/02/03 09:23:03 enami Exp $        */
+/*     $NetBSD: socket.h,v 1.50 2000/02/18 05:19:25 itojun Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -396,18 +396,20 @@
 };
 
 /* given pointer to struct cmsghdr, return pointer to data */
-#define        CMSG_DATA(cmsg)         ((u_char *)((cmsg) + 1))
+#define        CMSG_DATA(cmsg) \
+       ((u_char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)))
 
 /*
  * Alignment requirement for CMSG struct manipulation.
  * This is different from ALIGN() defined in ARCH/include/param.h.
  * XXX think again carefully about architecture dependencies.
  */
-#define CMSG_ALIGN(n)          (((n) + 3) & ~3)
+#define CMSG_ALIGN(n)  (((n) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
 
 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
 #define        CMSG_NXTHDR(mhdr, cmsg) \
-       (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
+       (((caddr_t)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) + \
+                           CMSG_ALIGN(sizeof(struct cmsghdr)) > \
            (((caddr_t)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
            (struct cmsghdr *)NULL : \
            (struct cmsghdr *)((caddr_t)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len)))



Home | Main Index | Thread Index | Old Index