Skip to contentSkip to conversation

getifaddrs()

DISCUSSION Adrian Dabrowski 3 participants 3 messages Jul 5, 2012 – Jul 7, 2012 2 messages not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Version: manpages-dev 3.27-1ubuntu2

The example program source produces a Seg-Fault, when a device does not have an ifa->ifa_addr. (e.g. openvpn-tunnels, probably others (dialup?))

ORIGINAL:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
               family = ifa->ifa_addr->sa_family;

POSSIBLE FIX:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
		if (ifa->ifa_addr != NULL)
               		family = ifa->ifa_addr->sa_family;
		else
			family = -1;

Also it is not documented, that struct sockaddr *ifa_addr might be NULL.

best wishes and keep up the good work,
Adrian Dabrowski
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi,

Quoted 1 line · Adrian Dabrowski

Version: manpages-dev 3.27-1ubuntu2

You should upgrade your manpages-dev version:
http://packages.ubuntu.com/search?keywords=manpages-dev

Quoted 3 lines

The example program source produces a Seg-Fault, when a device does not have an ifa->ifa_addr. (e.g. openvpn-tunnels, probably others (dialup?))

Thanks for reporting the issue, don't hesitate to report similar reports *that still apply in current version*.

Quoted 3 lines

ORIGINAL:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
               family = ifa->ifa_addr->sa_family;

http://man7.org/linux/man-pages/man3/getifaddrs.3.html

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
               if (ifa->ifa_addr == NULL)
                   continue;

               family = ifa->ifa_addr->sa_family; 

It has been fixed by
http://git.kernel.org/?p=docs/man-pages/man-pages.git;a=commitdiff;h=ebd05fecfe

Quoted 9 lines

POSSIBLE FIX:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
		if (ifa->ifa_addr != NULL)
               		family = ifa->ifa_addr->sa_family;
		else
			family = -1;

Also it is not documented, that struct sockaddr *ifa_addr might be NULL.

Best regards.

Signature · 5 lines
Simon Paillard
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20120706192945.GA15283-8MNqHwMchPhGJ/[email protected]

#4 lore raw
Quoted 21 lines · Simon Paillard

Hi,

Quoted 1 line · Adrian Dabrowski

Version: manpages-dev 3.27-1ubuntu2

You should upgrade your manpages-dev version:
http://packages.ubuntu.com/search?keywords=manpages-dev

Quoted 3 lines

The example program source produces a Seg-Fault, when a device does not have an ifa->ifa_addr. (e.g. openvpn-tunnels, probably others (dialup?))

Thanks for reporting the issue, don't hesitate to report similar reports *that still apply in current version*.

Quoted 3 lines

ORIGINAL:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
               family = ifa->ifa_addr->sa_family;

http://man7.org/linux/man-pages/man3/getifaddrs.3.html

Quoted 16 lines
           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
               if (ifa->ifa_addr == NULL)
                   continue;

               family = ifa->ifa_addr->sa_family;

It has been fixed by
http://git.kernel.org/?p=docs/man-pages/man-pages.git;a=commitdiff;h=ebd05fecfe

Quoted 7 lines

POSSIBLE FIX:

           for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
              if (ifa->ifa_addr != NULL)
                              family = ifa->ifa_addr->sa_family;
              else
                      family = -1;

Adrian, thanks for the note.

Simon, thanks for the review. From the above, I think nothing needs to be applied, but:

Quoted 1 line
Quoted 1 line

Also it is not documented, that struct sockaddr *ifa_addr might be NULL.

I applied the following patch for 3.42:

[[

man3/getifaddrs.3 +2 -0
@@ -98,20 +98,22 @@ for a list of these flags).
 The
 .I ifa_addr
 field points to a structure containing the interface address.
 (The
 .I sa_family
 subfield should be consulted to determine the format of the
 address structure.)
+This field may contain a NULL pointer.
 .PP
 The
 .I ifa_netmask
 field points to a structure containing the netmask associated with
 .IR ifa_addr ,
 if applicable for the address family.
+This field may contain a NULL pointer.
 .PP
 Depending on whether the bit
 .B IFF_BROADCAST
 or
 .B IFF_POINTOPOINT
 is set in
 .I ifa_flags

]]

Thanks,

Michael

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html