Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Fix the log. mtod never returns NULL, so 'ip' is...



details:   https://anonhg.NetBSD.org/src/rev/a15d9f00e258
branches:  trunk
changeset: 321659:a15d9f00e258
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Mar 30 08:25:06 2018 +0000

description:
Fix the log. mtod never returns NULL, so 'ip' is always non-NULL, and the
'ip6' branch is never taken. As a result we log garbage on IPv6 packets.

Use ip_v instead.

diffstat:

 sys/netinet/tcp_input.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 50bac98bcca1 -r a15d9f00e258 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Fri Mar 30 07:22:59 2018 +0000
+++ b/sys/netinet/tcp_input.c   Fri Mar 30 08:25:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.402 2018/03/30 07:11:40 maxv Exp $     */
+/*     $NetBSD: tcp_input.c,v 1.403 2018/03/30 08:25:06 maxv Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.402 2018/03/30 07:11:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.403 2018/03/30 08:25:06 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3176,16 +3176,23 @@
 #ifdef INET6
                                struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
 #endif
-                               if (ip)
+
+                               switch (ip->ip_v) {
+                               case 4:
                                        in_print(buf, sizeof(buf),
                                            &ip->ip_src);
+                                       break;
 #ifdef INET6
-                               else if (ip6)
+                               case 6:
                                        in6_print(buf, sizeof(buf),
                                            &ip6->ip6_src);
+                                       break;
 #endif
-                               else
+                               default:
                                        strlcpy(buf, "(unknown)", sizeof(buf));
+                                       break;
+                               }
+
                                log(LOG_ERR, "TCP: invalid wscale %d from %s, "
                                    "assuming %d\n",
                                    tp->requested_s_scale, buf,



Home | Main Index | Thread Index | Old Index