mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 16:46:50 +01:00
ircd::rfc1035: Fix assertion and enforce name limitations.
This commit is contained in:
parent
15b25894d3
commit
fee9222e70
1 changed files with 9 additions and 3 deletions
|
@ -406,6 +406,13 @@ ircd::rfc1035::parse_name(const mutable_buffer &out,
|
||||||
for(uint8_t len(*pos++); len && pos + len < end(in); len = *pos++)
|
for(uint8_t len(*pos++); len && pos + len < end(in); len = *pos++)
|
||||||
{
|
{
|
||||||
const string_view label{pos, len};
|
const string_view label{pos, len};
|
||||||
|
if(unlikely(size(label) > LABEL_MAX))
|
||||||
|
throw error
|
||||||
|
{
|
||||||
|
"Single part of domain cannot exceed %zu characters",
|
||||||
|
LABEL_MAX
|
||||||
|
};
|
||||||
|
|
||||||
strlcat(out, label);
|
strlcat(out, label);
|
||||||
strlcat(out, ".");
|
strlcat(out, ".");
|
||||||
pos += len;
|
pos += len;
|
||||||
|
@ -413,15 +420,14 @@ ircd::rfc1035::parse_name(const mutable_buffer &out,
|
||||||
|
|
||||||
assert(ssize_t(pos - begin(in)) > 0);
|
assert(ssize_t(pos - begin(in)) > 0);
|
||||||
const size_t ret(pos - data(in));
|
const size_t ret(pos - data(in));
|
||||||
if(ret > size(out) - 1)
|
if(ret >= size(out))
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
"Name of length %zu larger than %zu and would be truncated",
|
"Name of length %zu larger than %zu and would be truncated",
|
||||||
size_t(pos - data(in)),
|
size_t(pos - data(in)),
|
||||||
NAME_MAX
|
size(out)
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(strnlen(data(out), size(out)) + 1 == ret);
|
|
||||||
assert(ret <= size(in));
|
assert(ret <= size(in));
|
||||||
assert(ret <= size(out));
|
assert(ret <= size(out));
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue