]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- Fix a bug in the SIOCGIFCONF interface scanning code.
authorTed Lemon <source@isc.org>
Sat, 13 Feb 1999 19:17:03 +0000 (19:17 +0000)
committerTed Lemon <source@isc.org>
Sat, 13 Feb 1999 19:17:03 +0000 (19:17 +0000)
- Fix a core dump in the interface scanner that crops up on Linux when
  an interface is specified on the command line.

common/dispatch.c

index 0a383a04d48c03f801b2f136530f06a6bf508490..775bada37571cd8d5d67981d232c479faf910202 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dispatch.c,v 1.47.2.9 1999/02/05 20:23:50 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dispatch.c,v 1.47.2.10 1999/02/13 19:17:03 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -79,6 +79,7 @@ void discover_interfaces (state)
        struct shared_network *share;
        struct sockaddr_in foo;
        int ir;
+       struct ifreq *tif;
 #ifdef ALIAS_NAMES_PERMUTED
        char *s;
 #endif
@@ -110,7 +111,7 @@ void discover_interfaces (state)
        for (i = 0; i < ic.ifc_len;) {
                struct ifreq *ifp = (struct ifreq *)((caddr_t)ic.ifc_req + i);
 #ifdef HAVE_SA_LEN
-               if (ifp -> ifr_addr.sa_len)
+               if (ifp -> ifr_addr.sa_len > sizeof (struct sockaddr))
                        i += (sizeof ifp -> ifr_name) + ifp -> ifr_addr.sa_len;
                else
 #endif
@@ -194,7 +195,6 @@ void discover_interfaces (state)
                           found, keep a pointer to ifreq structure in
                           which we found it. */
                        if (!tmp -> ifp) {
-                               struct ifreq *tif;
 #ifdef HAVE_SA_LEN
                                int len = ((sizeof ifp -> ifr_name) +
                                           ifp -> ifr_addr.sa_len);
@@ -276,7 +276,6 @@ void discover_interfaces (state)
        if (state == DISCOVER_UNCONFIGURED) {
                FILE *proc_dev;
                char buffer [256];
-               struct ifreq *tif;
                int skip = 2;
 
                proc_dev = fopen (PROCDEV_DEVICE, "r");
@@ -306,25 +305,10 @@ void discover_interfaces (state)
                                if (!strcmp (tmp -> name, name))
                                        break;
 
-                       /* If we found one, and it already has an ifreq
-                          structure, nothing more to do.. */
-                       if (tmp && tmp -> ifp)
+                       /* If we found one, nothing more to do.. */
+                       if (tmp)
                                continue;
 
-                       /* Make up an ifreq structure. */
-                       tif = (struct ifreq *)malloc (sizeof (struct ifreq));
-                       if (!tif)
-                               error ("no space to remember ifp.");
-                       memset (tif, 0, sizeof (struct ifreq));
-                       strcpy (tif -> ifr_name, name);
-
-                       /* Now, if we just needed the ifreq structure, hook
-                          it in and move on. */
-                       if (tmp) {
-                               tmp -> ifp = tif;
-                               continue;
-                       }
-
                        /* Otherwise, allocate one. */
                        tmp = ((struct interface_info *)
                               dmalloc (sizeof *tmp, "discover_interfaces"));
@@ -334,7 +318,6 @@ void discover_interfaces (state)
                        memset (tmp, 0, sizeof *tmp);
                        strcpy (tmp -> name, name);
 
-                       tmp -> ifp = tif;
                        tmp -> flags = ir;
                        tmp -> next = interfaces;
                        interfaces = tmp;
@@ -351,6 +334,16 @@ void discover_interfaces (state)
                struct sockaddr sa;
                int b, sk;
                
+               if (!tmp -> ifp) {
+                       /* Make up an ifreq structure. */
+                       tif = (struct ifreq *)malloc (sizeof (struct ifreq));
+                       if (!tif)
+                               error ("no space to remember ifp.");
+                       memset (tif, 0, sizeof (struct ifreq));
+                       strcpy (tif -> ifr_name, tmp -> name);
+                       tmp -> ifp = tif;
+               }
+
                /* Read the hardware address from this interface. */
                ifr = *tmp -> ifp;
                if (ioctl (sock, SIOCGIFHWADDR, &ifr) < 0)