Skip to content

Commit

Permalink
ares_expand_name(): fix formatting and handling of root name response
Browse files Browse the repository at this point in the history
Fixes issue introduced in prior commit with formatting and handling
of parsing a root name response which should not be escaped.

Fix By: Brad House
  • Loading branch information
bradh352 committed Jun 11, 2021
1 parent 362f91d commit 44c009b
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions src/lib/ares_expand_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,37 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
}
else
{
len = *p;
int name_len = *p;
len = name_len;
p++;

while (len--)
{
if (!isprint(*p)) {
/* Output as \DDD for consistency with RFC1035 5.1 */
*q++ = '\\';
*q++ = '0' + *p / 100;
*q++ = '0' + (*p % 100) / 10;
*q++ = '0' + (*p % 10);
} else if (is_reservedch(*p)) {
*q++ = '\\';
*q++ = *p;
} else {
*q++ = *p;
}
/* Output as \DDD for consistency with RFC1035 5.1, except
* for the special case of a root name response */
if (!isprint(*p) && !(name_len == 1 && *p == 0))
{

*q++ = '\\';
*q++ = '0' + *p / 100;
*q++ = '0' + (*p % 100) / 10;
*q++ = '0' + (*p % 10);
}
else if (is_reservedch(*p))
{
*q++ = '\\';
*q++ = *p;
}
else
{
*q++ = *p;
}
p++;
}
*q++ = '.';
}
}
}

if (!indir)
*enclen = aresx_uztosl(p + 1U - encoded);

Expand Down Expand Up @@ -194,21 +204,29 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
}
else if (top == 0x00)
{
offset = *encoded;
int name_len = *encoded;
offset = name_len;
if (encoded + offset + 1 >= abuf + alen)
return -1;
encoded++;

while (offset--)
{
if (!isprint(*encoded)) {
n += 4;
} else if (is_reservedch(*encoded)) {
n += 2;
} else {
n += 1;
}
if (!isprint(*encoded) && !(name_len == 1 && *encoded == 0))
{
n += 4;
}
else if (is_reservedch(*encoded))
{
n += 2;
}
else
{
n += 1;
}
encoded++;
}

n++;
}
else
Expand Down

0 comments on commit 44c009b

Please sign in to comment.