Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/dns_packet: Ignore spaces in unquoted DNS values #19

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/dns_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ inline tl::expected<const T *, DNSParseError> AdvanceReader(std::span<const std:
return ptr;
}

bool contains_unprintable_chars(std::string_view sv) {
bool contains_unprintable_chars_or_space(std::string_view sv) {
bool result = false;
for (const auto &c : sv) {
result |= c < ' ' || c > '~';
result |= c < '!' || c > '~';
}

return result;
Expand Down Expand Up @@ -160,7 +160,7 @@ tl::expected<DnsName, DNSParseError> ReadFromDNSNameFormat(std::span<const std::
// Add NULL terminator
name_parsed.buf[name_parsed.len] = '\0';

if (contains_unprintable_chars(std::string_view(name_parsed))) [[unlikely]]
if (contains_unprintable_chars_or_space(std::string_view(name_parsed))) [[unlikely]]
return tl::unexpected(DNSParseError::InvalidChar);

// Add one to count if jumped to account for 2 byte offset field instead of 1 byte NULL
Expand Down Expand Up @@ -320,7 +320,7 @@ tl::expected<ResourceRecord, DNSParseError> ParseResourceRecord(std::span<const
r_data.tag = UNWRAP_OR_RETURN(
ParseFixedName<CAA_TAG_MAX_SIZE>(rdata_bytes, reader, tag_length));

if (contains_unprintable_chars(std::string_view(r_data.tag))) [[unlikely]]
if (contains_unprintable_chars_or_space(std::string_view(r_data.tag))) [[unlikely]]
return tl::unexpected(DNSParseError::InvalidChar);

uint16_t value_len = rdata_bytes.end() - reader;
Expand Down
Loading