Copilot commented on code in PR #13420:
URL: https://github.com/apache/trafficserver/pull/13420#discussion_r4448001948


##########
src/proxy/hdrs/VersionConverter.cc:
##########
@@ -200,8 +201,27 @@ VersionConverter::_convert_req_from_2_to_1(HTTPHdr 
&header) const
   // :authority
   if (MIMEField *field = header.field_find(PSEUDO_HEADER_AUTHORITY);
       field != nullptr && field->value_is_valid(is_control_BIT | is_ws_BIT)) {
-    auto authority{field->value_get()};
-    header.m_http->u.req.m_url_impl->set_host(header.m_heap, authority, true);
+    auto value{field->value_get()};
+
+    // No host to parse, and url_parse_internet() reads *start before checking 
the length.
+    if (value.empty()) {
+      return ParseResult::ERROR;
+    }
+
+    // Copy out first: allocating from header.m_heap may coalesce it and free 
the field's storage.
+    ts::LocalBuffer<char> buf(value.length());
+    std::string_view      authority{buf.data(), value.length()};
+
+    std::copy(value.begin(), value.end(), buf.data());
+
+    // Require full consumption: url_parse_internet() stops at a '/', '?' or 
'#'.
+    const char *astart = authority.data();
+    const char *aend   = authority.data() + authority.length();
+
+    if (url_parse_internet(header.m_heap, header.m_http->u.req.m_url_impl, 
&astart, aend, true, true) != ParseResult::DONE ||
+        astart != aend) {
+      return ParseResult::ERROR;

Review Comment:
   Parsing `:authority` here can discard CONNECT port text before the fallback 
parser checks it: overflowing ports are cleared, and numeric port 0 is omitted 
during serialization. With `request_line_max_size=1024`, `example.com:` 
followed by 1,100 nines therefore bypasses the previous 414; with 
`strict_uri_parsing=2`, `example.com:0\x80` loses the byte that previously 
caused a 400. Preserve the original CONNECT target for serialization and 
fallback, or apply the configured URI and request-line checks before this lossy 
conversion; excluding CONNECT from the direct path alone does not preserve 
those checks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to