From patchwork Tue Jul 8 11:13:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1942 Received: (qmail 21934 invoked by alias); 8 Jul 2014 11:13:52 -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 21908 invoked by uid 89); 8 Jul 2014 11:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Tue, 8 Jul 2014 16:43:41 +0530 From: Siddhesh Poyarekar To: Andreas Schwab Cc: carlos@redhat.com, libc-alpha@sourceware.org Subject: Re: [PATCH] Do not fail if one of the two responses to AF_UNSPEC fails (BZ #14308) Message-ID: <20140708111341.GG609@spoyarek.pnq.redhat.com> References: <20140415162902.GA8469@spoyarek.pnq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) On Tue, Jul 08, 2014 at 11:43:41AM +0200, Andreas Schwab wrote: > Siddhesh Poyarekar writes: > > > diff --git a/resolv/res_query.c b/resolv/res_query.c > > index a9db837..4e6612c 100644 > > --- a/resolv/res_query.c > > +++ b/resolv/res_query.c > > @@ -382,7 +382,9 @@ __libc_res_nsearch(res_state statp, > > answer, anslen, answerp, > > answerp2, nanswerp2, resplen2, > > answerp2_malloced); > > - if (ret > 0 || trailing_dot) > > + if (ret > 0 || trailing_dot > > + /* If the second response is valid then we use that. */ > > + || (ret == 0 && answerp2 != NULL && resplen2 > 0)) > > That doesn't make sense, resplen2 is a pointer. I'm surprised that the > compiler does not warn about that. > > I think that answerp2 != NULL should be resplen2 != NULL. > Ugh, of course. I'll commit the following patch once it clears testing. Siddhesh commit 50ede648e6ff67e00b5a842d466994d0c657b1ae Author: Siddhesh Poyarekar Date: Tue Jul 8 16:40:24 2014 +0530 Check value at resplen2 if it is not NULL There was a typo in the previous patch due to which resplen2 was checked for non-zero instead of the value at resplen2. Fix that and improve the condition by checking resplen2 for non-NULL (instead of answerp2) and also adding the check in a third place. diff --git a/ChangeLog b/ChangeLog index 5786f45..89ba227 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2014-07-08 Siddhesh Poyarekar + * resolv/res_query.c (__libc_res_nsearch): Dereference resplen2 + after checking that it is non-NULL. + * sysdeps/i386/dl-machine.h: Define ELF_MACHINE_NO_REL. * localedata/tests-mbwc/dat_iswalnum.c [SHOJI_IS_RIGHT]: diff --git a/resolv/res_query.c b/resolv/res_query.c index 4e6612c..e4ee2a6 100644 --- a/resolv/res_query.c +++ b/resolv/res_query.c @@ -384,7 +384,7 @@ __libc_res_nsearch(res_state statp, answerp2_malloced); if (ret > 0 || trailing_dot /* If the second response is valid then we use that. */ - || (ret == 0 && answerp2 != NULL && resplen2 > 0)) + || (ret == 0 && resplen2 != NULL && *resplen2 > 0)) return (ret); saved_herrno = h_errno; tried_as_is++; @@ -424,8 +424,8 @@ __libc_res_nsearch(res_state statp, answer, anslen, answerp, answerp2, nanswerp2, resplen2, answerp2_malloced); - if (ret > 0 || (ret == 0 && answerp2 != NULL - && resplen2 > 0)) + if (ret > 0 || (ret == 0 && resplen2 != NULL + && *resplen2 > 0)) return (ret); if (answerp && *answerp != answer) { @@ -494,7 +494,8 @@ __libc_res_nsearch(res_state statp, answer, anslen, answerp, answerp2, nanswerp2, resplen2, answerp2_malloced); - if (ret > 0) + if (ret > 0 || (ret == 0 && resplen2 != NULL + && *resplen2 > 0)) return (ret); }