From patchwork Sat Sep 13 08:18:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 388880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D0591400BB for ; Sat, 13 Sep 2014 18:18:34 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; q=dns; s=default; b=npgie cjAq4dHkoa8aJlADuU0WJ4ePqtgs6x/cZEe4A9noxzj2IZ3DztS73mb3Ry80V+0i LUVj7eFmokCpPU9Dxxkb8LZTtj8jOTjhJu4ukkx+2s8ikaCwinQEocUJIortXUjf jYiAr8IKdxWpQDi2JbMvYU2n4Nv5XEsbazkcDo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; s=default; bh=645JFFBv+MV gfKBvIhcIdQlOuIQ=; b=SNlawctuUGvhR2SIHqgWRXmti93BvkFinUT79vgDvEb DxynbkPxQ8SxN+cLrQqlKwySpgOdD0moD65Cb0aRod9mlTQvXn4VbF8pFgh5m/GJ SsdCFoKRo9Z8aA+Ix1TUEIpiyDtGofs/i36RkKWHhnVYYRi9U7e/F2Rztn1+mbfk = Received: (qmail 19144 invoked by alias); 13 Sep 2014 08:18:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 19130 invoked by uid 89); 13 Sep 2014 08:18:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 X-HELO: mail-out.m-online.net X-Auth-Info: YG79biZsR5irw6qCr4mcDWk4nXG00oBqlEcdKrDwr/mfxTMlXvdD5TSjMTipRWK5 From: Andreas Schwab To: Allan McRae Cc: libc-alpha Subject: Re: Segfault in getifaddrs_internal in glibc-2.20 References: <5413EA84.3060901@archlinux.org> X-Yow: JAPAN is a WONDERFUL planet -- I wonder if we'll ever reach their level of COMPARATIVE SHOPPING... Date: Sat, 13 Sep 2014 10:18:20 +0200 In-Reply-To: <5413EA84.3060901@archlinux.org> (Allan McRae's message of "Sat, 13 Sep 2014 16:56:04 +1000") Message-ID: <87sijw6iib.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.93 (gnu/linux) MIME-Version: 1.0 Allan McRae writes: > diff --git a/sysdeps/unix/sysv/linux/ifaddrs.c > b/sysdeps/unix/sysv/linux/ifaddrs.c > index 2c04e17..1fa4960 100644 > --- a/sysdeps/unix/sysv/linux/ifaddrs.c > +++ b/sysdeps/unix/sysv/linux/ifaddrs.c > @@ -774,7 +774,7 @@ getifaddrs_internal (struct ifaddrs **ifap) > unsigned int preflen; > > if ((max_prefixlen > 0) && > - (ifam->ifa_prefixlen > max_prefixlen)) > + (max_prefixlen > ifam->ifa_prefixlen)) > preflen = max_prefixlen; > else > preflen = ifam->ifa_prefixlen; > > > This seems to fix the issue for them. After looking at the code for a > long time, I am still not sure if this is the correct fix. Can anyone > confirm/deny? That doesn't make any sense. As the name says, max_prefixlen is the limit for the prefix length, but this makes it always equal to max_prefixlen (which is always > 0 here). The bug is of course that commit d89b3d8 doesn't handle a prefix length of zero. Andreas. [BZ #17371] * sysdeps/unix/sysv/linux/ifaddrs.c (getifaddrs_internal): Fix last change to handle zero prefix length. --- sysdeps/unix/sysv/linux/ifaddrs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sysdeps/unix/sysv/linux/ifaddrs.c b/sysdeps/unix/sysv/linux/ifaddrs.c index 2c04e17..a47b2ed 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); } } }