Source-Changes-HG archive

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

[src/netbsd-1-6]: src/sys/net Pull up revision 1.128-1.130 via patch (request...



details:   https://anonhg.NetBSD.org/src/rev/97b0f9696b61
branches:  netbsd-1-6
changeset: 530694:97b0f9696b61
user:      tron <tron%NetBSD.org@localhost>
date:      Wed Sep 10 19:00:09 2003 +0000

description:
Pull up revision 1.128-1.130 via patch (requested by itojun in ticket #1406):
correct if_clone_lookup().  based on diff from Quentin Garnier
fix INT_MAX check in if_clone_lookup
correct number range handling.  David Young

diffstat:

 sys/net/if.c |  41 +++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 18 deletions(-)

diffs (72 lines):

diff -r dbb8ed9ad75e -r 97b0f9696b61 sys/net/if.c
--- a/sys/net/if.c      Wed Sep 10 18:54:32 2003 +0000
+++ b/sys/net/if.c      Wed Sep 10 19:00:09 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.104.4.2 2003/06/19 02:39:52 grant Exp $       */
+/*     $NetBSD: if.c,v 1.104.4.3 2003/09/10 19:00:09 tron Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.104.4.2 2003/06/19 02:39:52 grant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.104.4.3 2003/09/10 19:00:09 tron Exp $");
 
 #include "opt_inet.h"
 
@@ -757,32 +757,37 @@
 {
        struct if_clone *ifc;
        const char *cp;
-       int i;
+       int unit;
+
+       /* separate interface name from unit */
+       for (cp = name;
+           cp - name < IFNAMSIZ && *cp && (*cp < '0' || *cp > '9');
+           cp++)
+               continue;
 
-       for (ifc = LIST_FIRST(&if_cloners); ifc != NULL;) {
-               for (cp = name, i = 0; i < ifc->ifc_namelen; i++, cp++) {
-                       if (ifc->ifc_name[i] != *cp)
-                               goto next_ifc;
-               }
-               goto found_name;
- next_ifc:
-               ifc = LIST_NEXT(ifc, ifc_list);
+       if (cp == name || cp - name == IFNAMSIZ || !*cp)
+               return (NULL);  /* No name or unit number */
+
+       LIST_FOREACH(ifc, &if_cloners, ifc_list) {
+               if (strlen(ifc->ifc_name) == cp - name &&
+                   !strncmp(name, ifc->ifc_name, cp - name))
+                       break;
        }
 
-       /* No match. */
-       return (NULL);
+       if (ifc == NULL)
+               return (NULL);
 
- found_name:
-       for (i = 0; *cp != '\0'; cp++) {
-               if (*cp < '0' || *cp > '9') {
+       unit = 0;
+       while (cp - name < IFNAMSIZ && *cp) {
+               if (*cp < '0' || *cp > '9' || unit > INT_MAX / 10) {
                        /* Bogus unit number. */
                        return (NULL);
                }
-               i = (i * 10) + (*cp - '0');
+               unit = (unit * 10) + (*cp++ - '0');
        }
 
        if (unitp != NULL)
-               *unitp = i;
+               *unitp = unit;
        return (ifc);
 }
 



Home | Main Index | Thread Index | Old Index