Skip to content

Commit 87c1674

Browse files
committed
Add missing length octet for NSEC3 RR
1 parent 9b92536 commit 87c1674

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/generic/base16.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static really_inline int32_t parse_salt(
286286
size_t length = token->length / 2;
287287
uint8_t *octets = rdata->octets++;
288288
// FIXME: not quite right yet! we must not exceed 255 octets!
289-
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < length)
289+
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < (length + 1))
290290
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
291291
if (!base16_decode(token->data, token->length, rdata->octets, &length))
292292
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));

src/generic/base32.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ nonnull_all
5050
static really_inline int32_t parse_base32(
5151
parser_t *parser,
5252
const type_info_t *type,
53-
const rdata_info_t *item,
53+
const rdata_info_t *field,
5454
rdata_t *rdata,
5555
const token_t *token)
5656
{
5757
uint32_t state = 0;
5858

59+
size_t length = (token->length * 5) / 8;
60+
if (length > 255 || (uintptr_t)rdata->limit - (uintptr_t)rdata->octets < (length + 1))
61+
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
62+
63+
*rdata->octets++ = (uint8_t)length;
64+
5965
const char *p = token->data;
6066
for (;; p++) {
6167
const uint8_t ofs = b32rmap[(uint8_t)*p];
@@ -104,7 +110,7 @@ static really_inline int32_t parse_base32(
104110
}
105111

106112
if (p != token->data + token->length)
107-
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(item), NAME(type));
113+
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
108114
return 0;
109115
}
110116

src/haswell/base32.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ static really_inline int32_t parse_base32(
8585
const token_t *token)
8686
{
8787
size_t length = (token->length * 5) / 8;
88-
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < length)
88+
if (length > 255 || (uintptr_t)rdata->limit - (uintptr_t)rdata->octets < (length + 1))
8989
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
9090

91-
size_t decoded = base32hex_avx(rdata->octets, (const uint8_t*)token->data);
91+
size_t decoded = base32hex_avx(rdata->octets+1, (const uint8_t*)token->data);
9292
if (decoded != token->length)
9393
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
94-
rdata->octets += length;
94+
*rdata->octets = (uint8_t)length;
95+
rdata->octets += 1 + length;
9596
return 0;
9697
}
9798

src/westmere/base32.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ static really_inline int32_t parse_base32(
7474
const token_t *token)
7575
{
7676
size_t length = (token->length * 5) / 8;
77-
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < length)
77+
if (length > 255 || (uintptr_t)rdata->limit - (uintptr_t)rdata->octets < (length + 1))
7878
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
7979

80-
size_t decoded = base32hex_sse(rdata->octets, (const uint8_t*)token->data);
80+
size_t decoded = base32hex_sse(rdata->octets+1, (const uint8_t*)token->data);
8181
if (decoded != token->length)
8282
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
83-
rdata->octets += length;
83+
*rdata->octets = (uint8_t)length;
84+
rdata->octets += 1 + length;
8485
return 0;
8586
}
8687

0 commit comments

Comments
 (0)