Bug 683039 - Example code in getifaddrs(3) man page can crash
Summary: Example code in getifaddrs(3) man page can crash
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: man-pages
Version: 6.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Ivana Varekova
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-03-08 12:18 UTC by Daniel Berrangé
Modified: 2011-05-19 14:01 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 683038
Environment:
Last Closed: 2011-05-19 14:01:28 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:0679 0 normal SHIPPED_LIVE man-pages bug fix and enhancement update 2011-05-18 18:10:37 UTC

Description Daniel Berrangé 2011-03-08 12:18:53 UTC
Cloning from Fedora, because also seen with man-pages-3.22-12.el6.noarch

+++ This bug was initially created as a clone of Bug #683038 +++

Description of problem:
In the getifaddrs(3) manual page, there is an 'EXAMPLE' section which contains code demonstrating how to use the getifaddrs() API. This code is not robust and will crash depending on the host OS network configuration

# gcc -g -o if if.c 
# gdb ./if
(gdb) run
Starting program: /home/berrange/if 
lo  address family: 17 (AF_PACKET)
wlan0  address family: 17 (AF_PACKET)
virbr0  address family: 17 (AF_PACKET)
virbr0-nic  address family: 17 (AF_PACKET)

Program received signal SIGSEGV, Segmentation fault.
0x00000000004006f7 in main (argc=1, argv=0x7fffffffe1e8) at if.c:25
25	               family = ifa->ifa_addr->sa_family;
(gdb) print ifa->ifa_addr
$1 = (struct sockaddr *) 0x0
(gdb) print *ifa
$2 = {ifa_next = 0x602088, ifa_name = 0x602074 "tun0", ifa_flags = 69841, ifa_addr = 0x0, 
  ifa_netmask = 0x0, ifa_ifu = {ifu_broadaddr = 0x0, ifu_dstaddr = 0x0}, ifa_data = 0x6027b8}

This bit of the example code:


           /* Walk through linked list, maintaining head pointer so we
              can free list later */

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

Should be changed to

           /* Walk through linked list, maintaining head pointer so we
              can free list later */

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


ie, allow for  ifa->ifa_addr being possibly NULL


Version-Release number of selected component (if applicable):
man-pages-3.25-1.fc14.noarch
glibc-2.13-1.x86_64

How reproducible:
Only if 'ifconfig -a' shows an interface with "Link encap:UNSPEC", eg tun0 from a VPNC connection


Steps to Reproduce:
1. Start VPNC client
2. Run getifaddrs() example program
3.
  
Actual results:
$ ./if 
lo  address family: 17 (AF_PACKET)
wlan0  address family: 17 (AF_PACKET)
virbr0  address family: 17 (AF_PACKET)
virbr0-nic  address family: 17 (AF_PACKET)
Segmentation fault

Expected results:
$ ./if 
lo  address family: 17 (AF_PACKET)
wlan0  address family: 17 (AF_PACKET)
virbr0  address family: 17 (AF_PACKET)
virbr0-nic  address family: 17 (AF_PACKET)
tun0  address family: 0
eth0  address family: 17 (AF_PACKET)
lo  address family: 2 (AF_INET)
	address: <127.0.0.1>
wlan0  address family: 2 (AF_INET)
	address: <192....>
virbr0  address family: 2 (AF_INET)
	address: <192.....>
tun0  address family: 2 (AF_INET)
	address: <10.....>
lo  address family: 10 (AF_INET6)
	address: <::1>
wlan0  address family: 10 (AF_INET6)
	address: <2a01:....>
wlan0  address family: 10 (AF_INET6)
	address: <fe80:....>


Additional info:

Comment 5 errata-xmlrpc 2011-05-19 14:01:28 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0679.html


Note You need to log in before you can comment on or make changes to this bug.