about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-06 07:16:35 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-06 07:16:35 +0000
commitacf82eaf270b410e49dfe45fa836f1ba41b62bb6 (patch)
treeb7f7e6e0f214d153585f6bcf5ac71d8d5788f556
parent694b49cac3bc23de181b25191cf852672b35aadc (diff)
downloadglibc-acf82eaf270b410e49dfe45fa836f1ba41b62bb6.tar.gz
glibc-acf82eaf270b410e49dfe45fa836f1ba41b62bb6.tar.xz
glibc-acf82eaf270b410e49dfe45fa836f1ba41b62bb6.zip
[BZ #2499]
2006-05-06  Ulrich Drepper  <drepper@redhat.com>
	[BZ #2499]
	* resolv/res_query.c (__libc_res_nquery): If answerp != NULL,
	__libc_res_nsend might reallocate the buffer for the answer.  In
	this case we have to reload the HP pointer.
-rw-r--r--ChangeLog7
-rw-r--r--resolv/res_query.c6
2 files changed, 13 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 067d4fe566..3d8a63fc71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-05-06  Ulrich Drepper  <drepper@redhat.com>
+
+	[BZ #2499]
+	* resolv/res_query.c (__libc_res_nquery): If answerp != NULL,
+	__libc_res_nsend might reallocate the buffer for the answer.  In
+	this case we have to reload the HP pointer.
+
 2006-05-05  Ulrich Drepper  <drepper@redhat.com>
 
 	* stdio-common/vfscanf.c (memory_error): Remove definition.  Add
diff --git a/resolv/res_query.c b/resolv/res_query.c
index 0feba6687a..85bad97d2d 100644
--- a/resolv/res_query.c
+++ b/resolv/res_query.c
@@ -69,6 +69,7 @@ static const char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
 static const char rcsid[] = "$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $";
 #endif /* LIBC_SCCS and not lint */
 
+#include <assert.h>
 #include <sys/types.h>
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -151,6 +152,7 @@ __libc_res_nquery(res_state statp,
 			free (buf);
 		return (n);
 	}
+	assert (answerp == NULL || (void *) *answerp == (void *) answer);
 	n = __libc_res_nsend(statp, buf, n, answer, anslen, answerp);
 	if (use_malloc)
 		free (buf);
@@ -163,6 +165,10 @@ __libc_res_nquery(res_state statp,
 		return (n);
 	}
 
+	if (answerp != NULL)
+	  /* __libc_res_nsend might have reallocated the buffer.  */
+	  hp = (HEADER *) *answerp;
+
 	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
 #ifdef DEBUG
 		if (statp->options & RES_DEBUG)