This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Do not fail if one of the two responses to AF_UNSPEC fails (BZ #14308)


On Tue, Jul 08, 2014 at 11:43:41AM +0200, Andreas Schwab wrote:
> Siddhesh Poyarekar <siddhesh@redhat.com> 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 <siddhesh@redhat.com>
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  <siddhesh@redhat.com>
 
+	* 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);
 	}
 

Attachment: pgpT6_QZ1uVRv.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]