Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/tcpdump fix strict aliasing issues.



details:   https://anonhg.NetBSD.org/src/rev/24b92aaff67a
branches:  trunk
changeset: 768471:24b92aaff67a
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 17 10:48:02 2011 +0000

description:
fix strict aliasing issues.

diffstat:

 external/bsd/tcpdump/bin/Makefile        |   7 +--
 external/bsd/tcpdump/dist/extract.h      |  92 ++++++++++++++++++++++++++++++++
 external/bsd/tcpdump/dist/print-isakmp.c |  10 ++-
 3 files changed, 100 insertions(+), 9 deletions(-)

diffs (166 lines):

diff -r aa419dfdc7d9 -r 24b92aaff67a external/bsd/tcpdump/bin/Makefile
--- a/external/bsd/tcpdump/bin/Makefile Wed Aug 17 10:46:38 2011 +0000
+++ b/external/bsd/tcpdump/bin/Makefile Wed Aug 17 10:48:02 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.6 2011/06/22 02:49:43 mrg Exp $   
+#      $NetBSD: Makefile,v 1.7 2011/08/17 10:48:02 christos Exp $      
 
 WARNS?=        1       # XXX: need to cleanup later
 
@@ -89,8 +89,3 @@
        cp ${.ALLSRC} ${.TARGET}
 
 .include <bsd.prog.mk>
-
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS+=        -fno-strict-aliasing
-.endif
diff -r aa419dfdc7d9 -r 24b92aaff67a external/bsd/tcpdump/dist/extract.h
--- a/external/bsd/tcpdump/dist/extract.h       Wed Aug 17 10:46:38 2011 +0000
+++ b/external/bsd/tcpdump/dist/extract.h       Wed Aug 17 10:48:02 2011 +0000
@@ -21,6 +21,97 @@
  * @(#) Header: /tcpdump/master/tcpdump/extract.h,v 1.25 2006-01-30 16:20:07 hannes Exp (LBL)
  */
 
+#ifdef __NetBSD__
+#include <string.h>
+
+/*
+ * Do it the portable way and let the compiler optimize the code
+ */
+static inline uint16_t EXTRACT_16BITS(const void *p)
+{
+       uint16_t t;
+       memcpy(&t, p, sizeof(t));
+       return ntohs(t);
+}
+
+static inline uint32_t EXTRACT_24BITS(const void *p)
+{
+       uint8_t t[3];
+       memcpy(t, p, sizeof(t));
+       return
+           ((uint32_t)t[0] << 16) |
+           ((uint32_t)t[1] << 8) |
+           t[2];
+}
+
+static inline uint32_t EXTRACT_32BITS(const void *p)
+{
+       uint32_t t;
+       memcpy(&t, p, sizeof(t));
+       return ntohl(t);
+}
+
+static inline uint64_t EXTRACT_64BITS(const void *p)
+{
+       uint32_t t[2];
+       memcpy(&t[0], p, sizeof(t[0]));
+       memcpy(&t[1], (const uint8_t *)p + sizeof(t[0]), sizeof(t[1]));
+       return ((uint64_t)ntohl(t[0]) << 32) | ntohl(t[1]);
+}
+
+static inline uint8_t EXTRACT_LE_8BITS(const void *p)
+{
+       uint8_t t[1];
+       memcpy(t, p, sizeof(t));
+       return t[0];
+}
+
+static inline uint16_t EXTRACT_LE_16BITS(const void *p)
+{
+       uint8_t t[2];
+       memcpy(t, p, sizeof(t));
+       return
+           ((uint16_t)t[1] << 8) |
+           t[0];
+}
+
+static inline uint32_t EXTRACT_LE_24BITS(const void *p)
+{
+       uint8_t t[3];
+       memcpy(t, p, sizeof(t));
+       return
+           ((uint32_t)t[2] << 16) |
+           ((uint32_t)t[1] << 8) |
+           t[0];
+}
+
+static inline uint32_t EXTRACT_LE_32BITS(const void *p)
+{
+       uint8_t t[4];
+       memcpy(t, p, sizeof(t));
+       return
+           ((uint32_t)t[3] << 24) |
+           ((uint32_t)t[2] << 16) |
+           ((uint32_t)t[1] << 8) |
+           t[0];
+}
+
+static inline uint64_t EXTRACT_LE_64BITS(const void *p)
+{
+       uint8_t t[8];
+       memcpy(&t, p, sizeof(t));
+       return
+           ((uint64_t)t[7] << 56) |
+           ((uint64_t)t[6] << 48) |
+           ((uint64_t)t[5] << 40) |
+           ((uint64_t)t[4] << 32) |
+           ((uint64_t)t[3] << 24) |
+           ((uint64_t)t[2] << 16) |
+           ((uint64_t)t[1] << 8) |
+           t[0];
+}
+
+#else /* Fast & Loose */
 /*
  * Macros to extract possibly-unaligned big-endian integral values.
  */
@@ -128,3 +219,4 @@
                     (u_int64_t)*((const u_int8_t *)(p) + 2) << 16 | \
                     (u_int64_t)*((const u_int8_t *)(p) + 1) << 8 | \
                     (u_int64_t)*((const u_int8_t *)(p) + 0)))
+#endif /* __NetBSD__ */
diff -r aa419dfdc7d9 -r 24b92aaff67a external/bsd/tcpdump/dist/print-isakmp.c
--- a/external/bsd/tcpdump/dist/print-isakmp.c  Wed Aug 17 10:46:38 2011 +0000
+++ b/external/bsd/tcpdump/dist/print-isakmp.c  Wed Aug 17 10:48:02 2011 +0000
@@ -34,7 +34,7 @@
 static const char rcsid[] _U_ =
     "@(#) Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.61 2008-02-05 19:34:25 guy Exp (LBL)";
 #else
-__RCSID("$NetBSD: print-isakmp.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
+__RCSID("$NetBSD: print-isakmp.c,v 1.3 2011/08/17 10:48:02 christos Exp $");
 #endif
 #endif
 
@@ -2229,11 +2229,13 @@
        u_char np;
        int i;
        int phase;
+       uint32_t msgid;
        
        p = (const struct isakmp *)bp;
        ep = ndo->ndo_snapend;
        
-       phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
+       memcpy(&msgid, base->msgid, sizeof(msgid));
+       phase = (msgid == 0) ? 1 : 2;
        if (phase == 1)
                ND_PRINT((ndo," phase %d", phase));
        else
@@ -2400,11 +2402,13 @@
        const u_char *ep;
        u_char np;
        int phase;
+       uint32_t msgid;
 
        p = (const struct isakmp *)bp;
        ep = ndo->ndo_snapend;
 
-       phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
+       memcpy(&msgid, base->msgid, sizeof(msgid));
+       phase = (msgid == 0) ? 1 : 2;
        if (phase == 1)
                ND_PRINT((ndo, " parent_sa"));
        else



Home | Main Index | Thread Index | Old Index