Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix regressions #133

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

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/v1/core/url_parser_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ inline auto is_windows_drive_letter(std::string_view segment) noexcept {
}

inline auto is_single_dot_path_segment(std::string_view segment) noexcept {
return (segment == ".") || (segment == "%2E");
return (segment == ".") || (segment == "%2e") || (segment == "%2E");
}

auto is_double_dot_path_segment(std::string_view segment) noexcept {
return (segment == "..") || (segment == "%2E.") || (segment == ".%2E") || (segment == "%2E%2E");
return (segment == "..") || (segment == "%2e.") || (segment == ".%2e") || (segment == "%2e%2e") ||
(segment == "%2E.") || (segment == ".%2E") || (segment == "%2E%2E") || (segment == "%2E%2e") ||
(segment == "%%2E");
}

void shorten_path(std::string_view scheme, std::vector<std::string> &path) {
Expand Down
25 changes: 10 additions & 15 deletions src/v1/domain/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
#include "idna_code_point_map_iterator.hpp"
#include "punycode.hpp"

#if !defined(SKYR_DOMAIN_MAX_DOMAIN_LENGTH)
#define SKYR_DOMAIN_MAX_DOMAIN_LENGTH 253
#endif // !defined(SKYR_DOMAIN_MAX_DOMAIN_LENGTH)

#if !defined(SKYR_DOMAIN_MAX_LABEL_LENGTH)
#define SKYR_DOMAIN_MAX_LABEL_LENGTH 63
#endif // !defined(SKYR_LABEL_MAX_DOMAIN_LENGTH)

/// How many labels can be in a domain?
/// https://www.farsightsecurity.com/blog/txt-record/rrlabel-20171013/
Expand All @@ -41,7 +34,7 @@ auto map_code_points(
U32Range &&domain_name,
bool use_std3_ascii_rules,
bool transitional_processing,
static_vector<char32_t, SKYR_DOMAIN_MAX_DOMAIN_LENGTH> *result)
std::u32string *result)
-> tl::expected<void, domain_errc> {
auto range = views::map_code_points(domain_name, use_std3_ascii_rules, transitional_processing);
auto first = std::cbegin(range);
Expand All @@ -50,7 +43,7 @@ auto map_code_points(
if (!*it) {
return tl::make_unexpected((*it).error());
}
result->emplace_back((*it).value());
result->push_back((*it).value());
if (result->size() == result->max_size()) {
return tl::make_unexpected(domain_errc::invalid_length);
}
Expand Down Expand Up @@ -113,7 +106,7 @@ auto domain_to_ascii(
using namespace std::string_view_literals;

auto u32domain_name = unicode::views::as_u8(domain_name) | unicode::transforms::to_u32;
auto mapped_domain_name = static_vector<char32_t, SKYR_DOMAIN_MAX_DOMAIN_LENGTH>{};
auto mapped_domain_name = std::u32string{};
auto result = map_code_points(u32domain_name, use_std3_ascii_rules, transitional_processing, &mapped_domain_name);
if (!result) {
return tl::make_unexpected(result.error());
Expand All @@ -123,8 +116,7 @@ auto domain_to_ascii(
return std::u32string_view(std::addressof(*std::begin(label)), ranges::distance(label));
};

/// TODO: try this without allocating strings (e.g. for large strings that don't use SBO)
auto labels = static_vector<static_vector<char32_t, SKYR_DOMAIN_MAX_LABEL_LENGTH>, SKYR_DOMAIN_MAX_NUM_LABELS>{};
auto labels = static_vector<std::u32string, SKYR_DOMAIN_MAX_NUM_LABELS>{};
for (auto &&label : mapped_domain_name | ranges::views::split(U'.') | ranges::views::transform(to_string_view)) {
if (labels.size() == labels.max_size()) {
return tl::make_unexpected(domain_errc::too_many_labels);
Expand Down Expand Up @@ -174,15 +166,18 @@ auto domain_to_ascii(
labels.emplace_back();
}

constexpr auto max_domain_length = 253;
constexpr auto max_label_length = 63;

if (verify_dns_length) {
auto length = mapped_domain_name.size();
if ((length < 1) || (length > 253)) {
if ((length < 1) || (length > max_domain_length)) {
return tl::make_unexpected(domain_errc::invalid_length);
}

for (const auto &label : labels) {
auto label_length = label.size();
if ((label_length < 1) || (label_length > 63)) {
if ((label_length < 1) || (label_length > max_label_length)) {
return tl::make_unexpected(domain_errc::invalid_length);
}
}
Expand Down Expand Up @@ -213,7 +208,7 @@ auto domain_to_u8(std::string_view domain_name, [[maybe_unused]] bool *validatio
return std::string_view(std::addressof(*std::begin(label)), ranges::distance(label));
};

auto labels = static_vector<static_vector<char, SKYR_DOMAIN_MAX_LABEL_LENGTH>, SKYR_DOMAIN_MAX_NUM_LABELS>{};
auto labels = static_vector<std::string, SKYR_DOMAIN_MAX_NUM_LABELS>{};
for (auto &&label : domain_name | ranges::views::split('.') | ranges::views::transform(to_string_view)) {
if (labels.size() == labels.max_size()) {
return tl::make_unexpected(domain_errc::too_many_labels);
Expand Down
3 changes: 2 additions & 1 deletion tests/allocations/host_parsing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ int main() {
"[2001:0db8:0:0::1428:57ab]"sv,
"localhost"sv,
"a.b.c.d.e.f.g.h.i.j.k.l.example.com"sv,
"sub.llanfairpwllgwyngyllgogerychwndrwbwllllantysiliogogogoch.com"sv
"sub.llanfairpwllgwyngyllgogerychwndrwbwllllantysiliogogogoch.com"sv,
"i am a terrible host name and n\0t in any way.valid.but. i am useful to validate @llocation"sv
};

for (auto &&host_string : host_strings) {
Expand Down