Skip to content

Commit

Permalink
Tweak MimeHdr::get_host_port_values to not run over the end of the Te…
Browse files Browse the repository at this point in the history
…xtView. (#8468)

Fix for #8461
  • Loading branch information
SolidWallOfCode committed Nov 2, 2021
1 parent 3ac5bcc commit 055ca11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions proxy/hdrs/MIME.cc
Expand Up @@ -2282,20 +2282,15 @@ MIMEHdr::get_host_port_values(const char **host_ptr, ///< Pointer to host.
if (b) {
if ('[' == *b) {
auto idx = b.find(']');
if (idx <= b.size() && b[idx + 1] == ':') {
if (idx < b.size() - 1 && b[idx + 1] == ':') {
host = b.take_prefix_at(idx + 1);
port = b;
} else {
host = b;
}
} else {
auto x = b.split_prefix_at(':');
if (x) {
host = x;
port = b;
} else {
host = b;
}
host = b.take_prefix_at(':');
port = b;
}

if (host) {
Expand Down
11 changes: 3 additions & 8 deletions src/tscpp/util/unit_tests/test_TextView.cc
Expand Up @@ -275,20 +275,15 @@ TEST_CASE("TextView Affixes", "[libts][TextView]")
auto f_host = [](TextView b, TextView &host, TextView &port) -> void {
if ('[' == *b) {
auto idx = b.find(']');
if (idx <= b.size() && b[idx + 1] == ':') {
if (idx < b.size() - 1 && b[idx + 1] == ':') {
host = b.take_prefix_at(idx + 1);
port = b;
} else {
host = b;
}
} else {
auto x = b.split_prefix_at(':');
if (x) {
host = x;
port = b;
} else {
host = b;
}
host = b.take_prefix_at(':');
port = b;
}
};

Expand Down

0 comments on commit 055ca11

Please sign in to comment.