aboutsummaryrefslogtreecommitdiff
path: root/resolv/res_query.c
diff options
context:
space:
mode:
authorAurelien Jarno <aurel32@debian.org>2012-11-30 15:04:27 -0500
committerDavid S. Miller <davem@davemloft.net>2012-11-30 15:04:27 -0500
commitcc8bb21c8ad619148c022af6e39ca8a5086a6a88 (patch)
treef3410b5396aad70d5fcc55913c8781c8abfb5581 /resolv/res_query.c
parentb062e14ff3df0942d21c8904e3fca87fac25b85b (diff)
downloadglibc-cc8bb21c8ad619148c022af6e39ca8a5086a6a88.zip
glibc-cc8bb21c8ad619148c022af6e39ca8a5086a6a88.tar.gz
glibc-cc8bb21c8ad619148c022af6e39ca8a5086a6a88.tar.bz2
Fix assertion failures in resolver (BZ #13013).
[BZ #13013] * resolv/res_query.c(__libc_res_nquery): Assign hp and hp2 depending n and resplen2 to catch cases where answer equals answerp2.
Diffstat (limited to 'resolv/res_query.c')
-rw-r--r--resolv/res_query.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/resolv/res_query.c b/resolv/res_query.c
index abccd4a..1325f97 100644
--- a/resolv/res_query.c
+++ b/resolv/res_query.c
@@ -122,6 +122,7 @@ __libc_res_nquery(res_state statp,
int *resplen2)
{
HEADER *hp = (HEADER *) answer;
+ HEADER *hp2;
int n, use_malloc = 0;
u_int oflags = statp->_flags;
@@ -239,26 +240,25 @@ __libc_res_nquery(res_state statp,
/* __libc_res_nsend might have reallocated the buffer. */
hp = (HEADER *) *answerp;
- /* We simplify the following tests by assigning HP to HP2. It
- is easy to verify that this is the same as ignoring all
- tests of HP2. */
- HEADER *hp2 = answerp2 ? (HEADER *) *answerp2 : hp;
-
- if (n < (int) sizeof (HEADER) && answerp2 != NULL
- && *resplen2 > (int) sizeof (HEADER))
+ /* We simplify the following tests by assigning HP to HP2 or
+ vice versa. It is easy to verify that this is the same as
+ ignoring all tests of HP or HP2. */
+ if (answerp2 == NULL || *resplen2 < (int) sizeof (HEADER))
{
- /* Special case of partial answer. */
- assert (hp != hp2);
- hp = hp2;
+ hp2 = hp;
}
- else if (answerp2 != NULL && *resplen2 < (int) sizeof (HEADER)
- && n > (int) sizeof (HEADER))
+ else
{
- /* Special case of partial answer. */
- assert (hp != hp2);
- hp2 = hp;
+ hp2 = (HEADER *) *answerp2;
+ if (n < (int) sizeof (HEADER))
+ {
+ hp = hp2;
+ }
}
+ /* Make sure both hp and hp2 are defined */
+ assert((hp != NULL) && (hp2 != NULL));
+
if ((hp->rcode != NOERROR || ntohs(hp->ancount) == 0)
&& (hp2->rcode != NOERROR || ntohs(hp2->ancount) == 0)) {
#ifdef DEBUG