1 --- a/resolv/res_query.c 2010-05-04 05:27:23.000000000 -0600
2 +++ a/resolv/res_query.c 2012-08-03 13:43:10.761506047 -0600
3 @@ -122,6 +122,7 @@ __libc_res_nquery(res_state statp,
6 HEADER *hp = (HEADER *) answer;
9 u_int oflags = statp->_flags;
11 @@ -239,26 +240,25 @@ __libc_res_nquery(res_state statp,
12 /* __libc_res_nsend might have reallocated the buffer. */
13 hp = (HEADER *) *answerp;
15 - /* We simplify the following tests by assigning HP to HP2. It
16 - is easy to verify that this is the same as ignoring all
18 - HEADER *hp2 = answerp2 ? (HEADER *) *answerp2 : hp;
20 - if (n < (int) sizeof (HEADER) && answerp2 != NULL
21 - && *resplen2 > (int) sizeof (HEADER))
22 + /* We simplify the following tests by assigning HP to HP2 or
23 + vice versa. It is easy to verify that this is the same as
24 + ignoring all tests of HP or HP2. */
25 + if (answerp2 == NULL || *resplen2 < (int) sizeof (HEADER))
27 - /* Special case of partial answer. */
32 - else if (answerp2 != NULL && *resplen2 < (int) sizeof (HEADER)
33 - && n > (int) sizeof (HEADER))
36 - /* Special case of partial answer. */
39 + hp2 = (HEADER *) *answerp2;
40 + if (n < (int) sizeof (HEADER))
46 + /* Make sure both hp and hp2 are defined */
47 + assert((hp != NULL) && (hp2 != NULL));
49 if ((hp->rcode != NOERROR || ntohs(hp->ancount) == 0)
50 && (hp2->rcode != NOERROR || ntohs(hp2->ancount) == 0)) {
52 --- a/resolv/res_send.c 2012-08-03 13:31:26.622168278 -0600
53 +++ a/resolv/res_send.c 2012-08-03 13:43:11.881501862 -0600
54 @@ -549,7 +549,7 @@ __libc_res_nsend(res_state statp, const
55 ns, ansp, ansp2, nansp2, resplen2);
59 + if (n == 0 && (buf2 == NULL || *resplen2 == 0))
63 @@ -559,7 +559,7 @@ __libc_res_nsend(res_state statp, const
64 ansp2, nansp2, resplen2);
68 + if (n == 0 && (buf2 == NULL || *resplen2 == 0))
71 // XXX Check whether both requests failed or
72 @@ -1275,10 +1275,14 @@ send_dg(res_state statp,
73 (*thisresplenp > *thisanssizp)
74 ? *thisanssizp : *thisresplenp);
76 - if (recvresp1 || (buf2 != NULL && recvresp2))
77 + if (recvresp1 || (buf2 != NULL && recvresp2)) {
83 + /* No data from the first reply. */
85 /* We are waiting for a possible second reply. */
86 if (hp->id == anhp->id)