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