1 # http://sourceware.org/bugzilla/show_bug.cgi?id=13013
3 2011-07-21 Aurelien Jarno <aurel32@debian.org>
5 * resolv/res_query.c(__libc_res_nquery): Assign hp and hp2
6 depending n and resplen2 to catch cases where answer
9 diff --git a/resolv/res_query.c b/resolv/res_query.c
10 index 2f7cfaa..405fa68 100644
11 --- a/resolv/res_query.c
12 +++ b/resolv/res_query.c
13 @@ -122,6 +122,7 @@ __libc_res_nquery(res_state statp,
16 HEADER *hp = (HEADER *) answer;
18 int n, use_malloc = 0;
19 u_int oflags = statp->_flags;
21 @@ -239,26 +240,25 @@ __libc_res_nquery(res_state statp,
22 /* __libc_res_nsend might have reallocated the buffer. */
23 hp = (HEADER *) *answerp;
25 - /* We simplify the following tests by assigning HP to HP2. It
26 - is easy to verify that this is the same as ignoring all
28 - HEADER *hp2 = answerp2 ? (HEADER *) *answerp2 : hp;
30 - if (n < (int) sizeof (HEADER) && answerp2 != NULL
31 - && *resplen2 > (int) sizeof (HEADER))
32 + /* We simplify the following tests by assigning HP to HP2 or
33 + vice versa. It is easy to verify that this is the same as
34 + ignoring all tests of HP or HP2. */
35 + if (answerp2 == NULL || *resplen2 < (int) sizeof (HEADER))
37 - /* Special case of partial answer. */
42 - else if (answerp2 != NULL && *resplen2 < (int) sizeof (HEADER)
43 - && n > (int) sizeof (HEADER))
46 - /* Special case of partial answer. */
49 + hp2 = (HEADER *) *answerp2;
50 + if (n < (int) sizeof (HEADER))
56 + /* Make sure both hp and hp2 are defined */
57 + assert((hp != NULL) && (hp2 != NULL));
59 if ((hp->rcode != NOERROR || ntohs(hp->ancount) == 0)
60 && (hp2->rcode != NOERROR || ntohs(hp2->ancount) == 0)) {