summaryrefslogtreecommitdiff
path: root/ares_parse_ptr_reply.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-11-26 17:04:35 +0000
committerYang Tse <yangsita@gmail.com>2008-11-26 17:04:35 +0000
commit7e39e944ea483f8551b05f21e1235dead9fa3cd8 (patch)
tree98ce100053a3d6cab7f3f54ca910e8b1dfaba67f /ares_parse_ptr_reply.c
parent8781fb19f9f0423571bfa0c7ef35e12f58503e7e (diff)
downloadc-ares-7e39e944ea483f8551b05f21e1235dead9fa3cd8.tar.gz
c-ares-7e39e944ea483f8551b05f21e1235dead9fa3cd8.tar.bz2
c-ares-7e39e944ea483f8551b05f21e1235dead9fa3cd8.zip
Gerald Combs fixed a bug in ares_parse_ptr_reply() which would cause a
buffer to shrink instead of expand if a reply contained 8 or more records.
Diffstat (limited to 'ares_parse_ptr_reply.c')
-rw-r--r--ares_parse_ptr_reply.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ares_parse_ptr_reply.c b/ares_parse_ptr_reply.c
index c5d8e14..54fb560 100644
--- a/ares_parse_ptr_reply.c
+++ b/ares_parse_ptr_reply.c
@@ -55,6 +55,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
char *ptrname, *hostname, *rr_name, *rr_data;
struct hostent *hostent;
int aliascnt = 0;
+ int alias_alloc = 8;
char ** aliases;
/* Set *host to NULL for all failure cases. */
@@ -84,7 +85,7 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
/* Examine each answer resource record (RR) in turn. */
hostname = NULL;
- aliases = malloc(8 * sizeof(char *));
+ aliases = malloc(alias_alloc * sizeof(char *));
if (!aliases)
{
free(ptrname);
@@ -125,9 +126,10 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
}
strncpy(aliases[aliascnt], rr_data, strlen(rr_data)+1);
aliascnt++;
- if ((aliascnt%8)==0) {
+ if (aliascnt >= alias_alloc) {
char **ptr;
- ptr = realloc(aliases, (aliascnt/16+1) * sizeof(char *));
+ alias_alloc *= 2;
+ ptr = realloc(aliases, alias_alloc * sizeof(char *));
if(!ptr) {
status = ARES_ENOMEM;
break;