From 1258b0166dc6e68c2592be3410e54d5cb19bc04b Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 4 Feb 2016 16:34:47 -0500 Subject: deps: sync with upstream bagder/c-ares@2bae2d5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/5090 Reviewed-By: Saúl Ibarra Corretgé --- deps/cares/src/ares_parse_txt_reply.c | 49 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'deps/cares/src/ares_parse_txt_reply.c') diff --git a/deps/cares/src/ares_parse_txt_reply.c b/deps/cares/src/ares_parse_txt_reply.c index dabf73cd3f..4856b4cea3 100644 --- a/deps/cares/src/ares_parse_txt_reply.c +++ b/deps/cares/src/ares_parse_txt_reply.c @@ -44,9 +44,9 @@ #include "ares_data.h" #include "ares_private.h" -int -ares_parse_txt_reply (const unsigned char *abuf, int alen, - struct ares_txt_reply **txt_out) +static int +ares__parse_txt_reply (const unsigned char *abuf, int alen, + int ex, void **txt_out) { size_t substr_len; unsigned int qdcount, ancount, i; @@ -55,9 +55,9 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, int status, rr_type, rr_class, rr_len; long len; char *hostname = NULL, *rr_name = NULL; - struct ares_txt_reply *txt_head = NULL; - struct ares_txt_reply *txt_last = NULL; - struct ares_txt_reply *txt_curr; + struct ares_txt_ext *txt_head = NULL; + struct ares_txt_ext *txt_last = NULL; + struct ares_txt_ext *txt_curr; /* Set *txt_out to NULL for all failure cases. */ *txt_out = NULL; @@ -82,7 +82,7 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, if (aptr + len + QFIXEDSZ > abuf + alen) { - free (hostname); + ares_free (hostname); return ARES_EBADRESP; } aptr += len + QFIXEDSZ; @@ -134,7 +134,8 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, } /* Allocate storage for this TXT answer appending it to the list */ - txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY); + txt_curr = ares_malloc_data(ex ? ARES_DATATYPE_TXT_EXT : + ARES_DATATYPE_TXT_REPLY); if (!txt_curr) { status = ARES_ENOMEM; @@ -150,9 +151,10 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, } txt_last = txt_curr; - txt_curr->record_start = strptr == aptr; + if (ex) + txt_curr->record_start = (strptr == aptr); txt_curr->length = substr_len; - txt_curr->txt = malloc (substr_len + 1/* Including null byte */); + txt_curr->txt = ares_malloc (substr_len + 1/* Including null byte */); if (txt_curr->txt == NULL) { status = ARES_ENOMEM; @@ -169,8 +171,14 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, } } + /* Propagate any failures */ + if (status != ARES_SUCCESS) + { + break; + } + /* Don't lose memory in the next iteration */ - free (rr_name); + ares_free (rr_name); rr_name = NULL; /* Move on to the next record */ @@ -178,9 +186,9 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, } if (hostname) - free (hostname); + ares_free (hostname); if (rr_name) - free (rr_name); + ares_free (rr_name); /* clean up on error */ if (status != ARES_SUCCESS) @@ -195,3 +203,18 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen, return ARES_SUCCESS; } + +int +ares_parse_txt_reply (const unsigned char *abuf, int alen, + struct ares_txt_reply **txt_out) +{ + return ares__parse_txt_reply(abuf, alen, 0, (void **) txt_out); +} + + +int +ares_parse_txt_reply_ext (const unsigned char *abuf, int alen, + struct ares_txt_ext **txt_out) +{ + return ares__parse_txt_reply(abuf, alen, 1, (void **) txt_out); +} -- cgit v1.2.3