summaryrefslogtreecommitdiff
path: root/ares_expand_name.c
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-09 02:18:45 (GMT)
committerYu Jiung <jiung.yu@samsung.com>2016-11-09 02:18:55 (GMT)
commiteb886f120599b2a184db20b527db6dfdfcb7852e (patch)
treeb49d8075742c4a27b237fa183cb68670e421d398 /ares_expand_name.c
parentb6627e2c19506bd30328969ea8aab73fa0945f36 (diff)
downloadc-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.zip
c-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.tar.gz
c-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.tar.bz2
Imported Upstream version 1.11.0upstream/1.11.0refs/changes/18/96418/1
Change-Id: I238c24b75a10aa902d9bc4076ed68b76b5e2a750
Diffstat (limited to 'ares_expand_name.c')
-rw-r--r--ares_expand_name.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/ares_expand_name.c b/ares_expand_name.c
index 2aa12bc..738be8d 100644
--- a/ares_expand_name.c
+++ b/ares_expand_name.c
@@ -74,7 +74,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
if (nlen.sig < 0)
return ARES_EBADNAME;
- *s = malloc(nlen.uns + 1);
+ *s = ares_malloc(nlen.uns + 1);
if (!*s)
return ARES_ENOMEM;
q = *s;
@@ -129,7 +129,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
if (q > *s)
*(q - 1) = 0;
else
- *q = 0; /* zero terminate */
+ *q = 0; /* zero terminate; LCOV_EXCL_LINE: empty names exit above */
return ARES_SUCCESS;
}
@@ -140,7 +140,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
static int name_length(const unsigned char *encoded, const unsigned char *abuf,
int alen)
{
- int n = 0, offset, indir = 0;
+ int n = 0, offset, indir = 0, top;
/* Allow the caller to pass us abuf + alen and have us check for it. */
if (encoded >= abuf + alen)
@@ -148,7 +148,8 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
while (*encoded)
{
- if ((*encoded & INDIR_MASK) == INDIR_MASK)
+ top = (*encoded & INDIR_MASK);
+ if (top == INDIR_MASK)
{
/* Check the offset and go there. */
if (encoded + 1 >= abuf + alen)
@@ -164,7 +165,7 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
if (++indir > alen)
return -1;
}
- else
+ else if (top == 0x00)
{
offset = *encoded;
if (encoded + offset + 1 >= abuf + alen)
@@ -177,6 +178,13 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
}
n++;
}
+ else
+ {
+ /* RFC 1035 4.1.4 says other options (01, 10) for top 2
+ * bits are reserved.
+ */
+ return -1;
+ }
}
/* If there were any labels at all, then the number of dots is one