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

Bug#357152: linked list returned by getifaddrs() contains structures without any address data



package libc6
tags 357152 + patch
thankyou

Hi,

these are my results:

The list getifaddrs() returns starts with an enumeration of
all interfaces, each one associated with a struct sockaddr_ll
(containing the index this interface has in the kernel, and
its L2 address, if applicable). These data sets are obtained
by issuing a netlink dump request with the type GETLINK.
(Following that is a dump of type GETADDR, but that part is
working fine and unrelated to this bug.)

The problem now is that this sockaddr_ll struct only gets filled
if the netlink response message carries a rt option of type
IFLA_ADDRESS or IFLA_BROADCAST, both of which don't make sense in
the case of point-to-point interfaces.

I think this should be changed, because the sockaddr_ll struct
is even valid without address info, i.e. you can open a raw
socket and bind it to a ppp device with only AF_PACKET and the
interface number filled in. getifaddrs() shouldn't withhold
this piece of information.

I propose the attached patch, which sets the sll_family and
sll_ifindex members in advance (before going through the rt
options) so they are always valid, even if no address data is
found.

Tell me if you need any further input from me.


Regards,

Jan

-- 
Jan C. Nordholz
<jckn At gmx net>
--- tmp/glibc-2.3.999/glibc-2.4/sysdeps/unix/sysv/linux/ifaddrs.c.orig	2005-06-14 01:54:54.000000000 +0200
+++ tmp/glibc-2.3.999/glibc-2.4/sysdeps/unix/sysv/linux/ifaddrs.c	2006-03-23 22:36:18.000000000 +0100
@@ -504,6 +504,9 @@
 	      ifa_index = map_newlink (ifim->ifi_index - 1, ifas,
 				       map_newlink_data, newlink);
 	      ifas[ifa_index].ifa.ifa_flags = ifim->ifi_flags;
+	      ifas[ifa_index].addr.sl.sll_family = AF_PACKET;
+	      ifas[ifa_index].addr.sl.sll_ifindex = ifim->ifi_index;
+	      ifas[ifa_index].ifa.ifa_addr = &ifas[ifa_index].addr.sa;
 
 	      while (RTA_OK (rta, rtasize))
 		{
@@ -515,12 +518,9 @@
 		    case IFLA_ADDRESS:
 		      if (rta_payload <= sizeof (ifas[ifa_index].addr))
 			{
-			  ifas[ifa_index].addr.sl.sll_family = AF_PACKET;
 			  memcpy (ifas[ifa_index].addr.sl.sll_addr,
 				  (char *) rta_data, rta_payload);
 			  ifas[ifa_index].addr.sl.sll_halen = rta_payload;
-			  ifas[ifa_index].addr.sl.sll_ifindex
-			    = ifim->ifi_index;
 			  ifas[ifa_index].addr.sl.sll_hatype = ifim->ifi_type;
 
 			  ifas[ifa_index].ifa.ifa_addr
@@ -531,12 +531,9 @@
 		    case IFLA_BROADCAST:
 		      if (rta_payload <= sizeof (ifas[ifa_index].broadaddr))
 			{
-			  ifas[ifa_index].broadaddr.sl.sll_family = AF_PACKET;
 			  memcpy (ifas[ifa_index].broadaddr.sl.sll_addr,
 				  (char *) rta_data, rta_payload);
 			  ifas[ifa_index].broadaddr.sl.sll_halen = rta_payload;
-			  ifas[ifa_index].broadaddr.sl.sll_ifindex
-			    = ifim->ifi_index;
 			  ifas[ifa_index].broadaddr.sl.sll_hatype
 			    = ifim->ifi_type;
 

Reply to: