From a7b872687073decdcc7effc2289877d69058aca9 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 13 Sep 2014 10:10:29 +0200 Subject: [PATCH] Handle zero prefix length in getifaddrs (BZ #17371) --- ChangeLog | 6 ++++++ NEWS | 2 +- sysdeps/unix/sysv/linux/ifaddrs.c | 11 ++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e316f8c3b2..a40fb4622c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-09-15 Andreas Schwab + + [BZ #17371] + * sysdeps/unix/sysv/linux/ifaddrs.c (getifaddrs_internal): Fix + last change to handle zero prefix length. + 2014-09-15 Siddhesh Poyarekar * sysdeps/posix/sysconf.c (__sysconf): Return -1 for diff --git a/NEWS b/NEWS index 680c265c68..231159071e 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ Version 2.21 * The following bugs are resolved with this release: - 17363, 17370. + 17363, 17370, 17371. Version 2.20 diff --git a/sysdeps/unix/sysv/linux/ifaddrs.c b/sysdeps/unix/sysv/linux/ifaddrs.c index 2c04e172ce..a47b2edcad 100644 --- a/sysdeps/unix/sysv/linux/ifaddrs.c +++ b/sysdeps/unix/sysv/linux/ifaddrs.c @@ -770,20 +770,17 @@ getifaddrs_internal (struct ifaddrs **ifap) if (cp != NULL) { - char c; unsigned int preflen; - if ((max_prefixlen > 0) && - (ifam->ifa_prefixlen > max_prefixlen)) + if (ifam->ifa_prefixlen > max_prefixlen) preflen = max_prefixlen; else preflen = ifam->ifa_prefixlen; - for (i = 0; i < ((preflen - 1) / 8); i++) + for (i = 0; i < preflen / 8; i++) *cp++ = 0xff; - c = 0xff; - c <<= ((128 - preflen) % 8); - *cp = c; + if (preflen % 8) + *cp = 0xff << (8 - preflen % 8); } } }