Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/netinet Apply patch, requested by christos in ticket ...



details:   https://anonhg.NetBSD.org/src/rev/915907f85403
branches:  netbsd-8
changeset: 935674:915907f85403
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Jul 08 13:48:36 2020 +0000

description:
Apply patch, requested by christos in ticket #1566:

Deduplicate more code and avoid use of uninitialized variables.

diffstat:

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

diffs (78 lines):

diff -r 524296652915 -r 915907f85403 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Tue Jul 07 19:58:25 2020 +0000
+++ b/sys/netinet/tcp_input.c   Wed Jul 08 13:48:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.357.4.4 2020/07/07 11:56:57 martin Exp $       */
+/*     $NetBSD: tcp_input.c,v 1.357.4.5 2020/07/08 13:48:36 martin 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.357.4.4 2020/07/07 11:56:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.357.4.5 2020/07/08 13:48:36 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1272,6 +1272,12 @@
        }
 #endif
 
+       IP6_EXTHDR_GET(th, struct tcphdr *, m, toff, sizeof(struct tcphdr));
+       if (th == NULL) {
+               TCP_STATINC(TCP_STAT_RCVSHORT);
+               return;
+       }
+
        /*
         * Enforce alignment requirements that are violated in
         * some cases, see kern/50766 for details.
@@ -1301,15 +1307,8 @@
        case 4:
                af = AF_INET;
                iphlen = sizeof(struct ip);
-               IP6_EXTHDR_GET(th, struct tcphdr *, m, toff,
-                       sizeof(struct tcphdr));
-               if (th == NULL) {
-                       TCP_STATINC(TCP_STAT_RCVSHORT);
-                       return;
-               }
                /* We do the checksum after PCB lookup... */
                len = ntohs(ip->ip_len);
-               tlen = len - toff;
                iptos = ip->ip_tos;
                break;
 #endif
@@ -1317,13 +1316,6 @@
        case 6:
                iphlen = sizeof(struct ip6_hdr);
                af = AF_INET6;
-               IP6_EXTHDR_GET(th, struct tcphdr *, m, toff,
-                       sizeof(struct tcphdr));
-               if (th == NULL) {
-                       TCP_STATINC(TCP_STAT_RCVSHORT);
-                       return;
-               }
-
                /* Be proactive about malicious use of IPv4 mapped address */
                if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
                    IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
@@ -1355,7 +1347,6 @@
 
                /* We do the checksum after PCB lookup... */
                len = m->m_pkthdr.len;
-               tlen = len - toff;
                iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
                break;
 #endif
@@ -1364,6 +1355,8 @@
                return;
        }
 
+       tlen = len - toff;
+
        /*
         * Check that TCP offset makes sense,
         * pull out TCP options and adjust length.              XXX



Home | Main Index | Thread Index | Old Index