]> granicus.if.org Git - sudo/commitdiff
fixed for AIX
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 22 Dec 1995 02:53:12 +0000 (02:53 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 22 Dec 1995 02:53:12 +0000 (02:53 +0000)
now deal if num_interfaces == 0 (should not happen)

interfaces.c

index 22701477c2a9088b0783f98ed1055b5e9e427d23..1ee1c98e75b18c00057efb5777bb5413f0b7e47f 100644 (file)
@@ -163,10 +163,11 @@ void load_interfaces()
 
        /* set i to the subscript of the next interface */
 #ifdef HAVE_SA_LEN
-       i += sizeof(ifreq.ifr_name) + ifreq.ifr_addr.sa_len;
-#else
-       i += sizeof(struct ifreq);
+       if (ifreq.ifr_addr.sa_len > sizeof(ifreq.ifr_addr))
+           i += sizeof(ifreq.ifr_name) + ifreq.ifr_addr.sa_len;
+       else
 #endif /* HAVE_SA_LEN */
+           i += sizeof(struct ifreq);
 
        /* skip duplicates and interfaces with NULL addresses */
        sin = (struct sockaddr_in *) &ifr->ifr_addr;
@@ -231,12 +232,17 @@ void load_interfaces()
 
     /* if there were bogus entries, realloc the array */
     if (n != num_interfaces) {
-       interfaces = (struct interface *) realloc(interfaces,
-           sizeof(struct interface) * num_interfaces);
-       if (interfaces == NULL) {
-           perror("realloc");
-           (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-           exit(1);
+       /* it is unlikely that num_interfaces will be 0 but who knows... */
+       if (num_interfaces != 0) {
+           interfaces = (struct interface *) realloc(interfaces,
+               sizeof(struct interface) * num_interfaces);
+           if (interfaces == NULL) {
+               perror("realloc");
+               (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
+               exit(1);
+           }
+       } else {
+           (void) free(interfaces);
        }
     }
 }