Skip to content

Commit 3c22a02

Browse files
authored
Sigsegv, adress->ifa_addr can be a null pointer
I get sigseg when try to execute it (ubuntu 16.04, gcc 5.4.0). According to http://man7.org/linux/man-pages/man3/getifaddrs.3.html : "The ifa_addr... .This field may contain a null pointer." Little check for null pointer proposed. Or may be it'll be better with for cycle since two lines of adress = adress->ifa_addr in my proposal.
1 parent 358e831 commit 3c22a02

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

chap01/unix_list.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ int main() {
4040

4141
struct ifaddrs *address = addresses;
4242
while(address) {
43+
if (address->ifa_addr == NULL) {
44+
address = address->ifa_next;
45+
continue;
46+
}
4347
int family = address->ifa_addr->sa_family;
4448
if (family == AF_INET || family == AF_INET6) {
4549

0 commit comments

Comments
 (0)