Skip to content

Commit

Permalink
Revert "deps: backport b5135bbc from c-ares repo"
Browse files Browse the repository at this point in the history
This reverts commit 896e193.

Proper handling of TXT records requires API change, we can't afford it
in v0.10.

See nodejs#7371 for details.
  • Loading branch information
indutny committed Apr 24, 2014
1 parent 75bc11c commit 4601e7c
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions deps/cares/src/ares_parse_txt_reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int
ares_parse_txt_reply (const unsigned char *abuf, int alen,
struct ares_txt_reply **txt_out)
{
size_t substr_len;
size_t substr_len, str_len;
unsigned int qdcount, ancount, i;
const unsigned char *aptr;
const unsigned char *strptr;
Expand Down Expand Up @@ -116,6 +116,23 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
/* Check if we are really looking at a TXT record */
if (rr_class == C_IN && rr_type == T_TXT)
{
/* Allocate storage for this TXT answer appending it to the list */
txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
if (!txt_curr)
{
status = ARES_ENOMEM;
break;
}
if (txt_last)
{
txt_last->next = txt_curr;
}
else
{
txt_head = txt_curr;
}
txt_last = txt_curr;

/*
* There may be multiple substrings in a single TXT record. Each
* substring may be up to 255 characters in length, with a
Expand All @@ -124,49 +141,36 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
* substrings contained therein.
*/

/* Compute total length to allow a single memory allocation */
strptr = aptr;
while (strptr < (aptr + rr_len))
{
substr_len = (unsigned char)*strptr;
if (strptr + substr_len + 1 > aptr + rr_len)
{
status = ARES_EBADRESP;
break;
}

++strptr;

/* Allocate storage for this TXT answer appending it to the list */
txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
if (!txt_curr)
{
status = ARES_ENOMEM;
break;
}
if (txt_last)
{
txt_last->next = txt_curr;
}
else
{
txt_head = txt_curr;
}
txt_last = txt_curr;

txt_curr->length = substr_len;
txt_curr->txt = malloc (substr_len + 1/* Including null byte */);
if (txt_curr->txt == NULL)
{
status = ARES_ENOMEM;
break;
}
memcpy ((char *) txt_curr->txt, strptr, substr_len);

/* Make sure we NULL-terminate */
txt_curr->txt[substr_len] = 0;
txt_curr->length += substr_len;
strptr += substr_len + 1;
}

/* Including null byte */
txt_curr->txt = malloc (txt_curr->length + 1);
if (txt_curr->txt == NULL)
{
status = ARES_ENOMEM;
break;
}

/* Step through the list of substrings, concatenating them */
str_len = 0;
strptr = aptr;
while (strptr < (aptr + rr_len))
{
substr_len = (unsigned char)*strptr;
strptr++;
memcpy ((char *) txt_curr->txt + str_len, strptr, substr_len);
str_len += substr_len;
strptr += substr_len;
}
/* Make sure we NULL-terminate */
*((char *) txt_curr->txt + txt_curr->length) = '\0';
}

/* Don't lose memory in the next iteration */
Expand Down

0 comments on commit 4601e7c

Please sign in to comment.