Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
properly handle invalid port input with non-digit characters
  • Loading branch information
mertcanaltin committed Jan 11, 2025
commit cf1c3a2d25dd4319b22c02229cfbb596fd39a830
7 changes: 7 additions & 0 deletions src/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,13 @@ bool url::set_port(const std::string_view input) {
port = std::nullopt;
return true;
}

auto non_digit_pos = std::find_if_not(trimmed.begin(), trimmed.end(),
ada::unicode::is_ascii_digit);
if (non_digit_pos != trimmed.end()) {
trimmed.erase(non_digit_pos, trimmed.end());
}

// Input should not start with control characters.
if (ada::unicode::is_c0_control_or_space(trimmed.front())) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions src/url_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ bool url_aggregator::set_port(const std::string_view input) {
clear_port();
return true;
}

auto non_digit_pos = std::find_if_not(trimmed.begin(), trimmed.end(),
ada::unicode::is_ascii_digit);
if (non_digit_pos != trimmed.end()) {
trimmed.erase(non_digit_pos, trimmed.end());
}

// Input should not start with control characters.
if (ada::unicode::is_c0_control_or_space(trimmed.front())) {
return false;
Expand Down