Print this page
8429 getallifaddrs dereferences invalid pointer causing SIGSEGV
Reviewed by: Sebastian Wiedenroth <sw@core.io>
Reviewed by: Yuri Pankov <yuripv@gmx.com>
Reviewed by: Toomas Soome <tsoome@me.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libsocket/inet/getifaddrs.c
          +++ new/usr/src/lib/libsocket/inet/getifaddrs.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2017 RackTop Systems.
  24   25   */
  25   26  
  26   27  #include <netdb.h>
  27   28  #include <nss_dbdefs.h>
  28   29  #include <netinet/in.h>
  29   30  #include <sys/socket.h>
  30   31  #include <string.h>
  31   32  #include <stdio.h>
  32   33  #include <sys/sockio.h>
  33   34  #include <sys/types.h>
↓ open down ↓ 61 lines elided ↑ open up ↑
  95   96          struct lifreq *lifrp;
  96   97          struct lifreq lifrl;
  97   98          int ret;
  98   99          int s, n, numifs;
  99  100          struct ifaddrs *curr, *prev;
 100  101          sa_family_t lifr_af;
 101  102          int sock4;
 102  103          int sock6;
 103  104          int err;
 104  105  
      106 +        /*
      107 +         * Initialize ifap to NULL so we can safely call freeifaddrs
      108 +         * on it in case of error.
      109 +         */
      110 +        if (ifap == NULL)
      111 +                return (EINVAL);
      112 +        *ifap = NULL;
      113 +
 105  114          if ((sock4 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
 106  115                  return (-1);
 107  116          if ((sock6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
 108  117                  err = errno;
 109  118                  close(sock4);
 110  119                  errno = err;
 111  120                  return (-1);
 112  121          }
 113  122  
 114  123  retry:
↓ open down ↓ 1 lines elided ↑ open up ↑
 116  125          ret = getallifs(sock4, af, &buf, &numifs, (flags & ~LIFC_ENABLED));
 117  126          if (ret != 0)
 118  127                  goto fail;
 119  128  
 120  129          /*
 121  130           * Loop through the interfaces obtained from SIOCGLIFCOMF
 122  131           * and retrieve the addresses, netmask and flags.
 123  132           */
 124  133          prev = NULL;
 125  134          lifrp = buf;
 126      -        *ifap = NULL;
 127  135          for (n = 0; n < numifs; n++, lifrp++) {
 128  136  
 129  137                  /* Prepare for the ioctl call */
 130  138                  (void) strncpy(lifrl.lifr_name, lifrp->lifr_name,
 131  139                      sizeof (lifrl.lifr_name));
 132  140                  lifr_af = lifrp->lifr_addr.ss_family;
 133  141                  if (af != AF_UNSPEC && lifr_af != af)
 134  142                          continue;
 135  143  
 136  144                  s = (lifr_af == AF_INET ? sock4 : sock6);
↓ open down ↓ 136 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX