Skip to content

Commit c36ca8a

Browse files
authored
fix(http2): non-utf8 char in Connection header may cause panic when calling to_str (#4019)
1 parent dc9962e commit c36ca8a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/proto/h2/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
6464
"Connection header illegal in HTTP/2: {}",
6565
CONNECTION.as_str()
6666
);
67-
let header_contents = header.to_str().unwrap();
68-
6967
// A `Connection` header may have a comma-separated list of names of other headers that
7068
// are meant for only this specific connection.
7169
//
7270
// Iterate these names and remove them as headers. Connection-specific headers are
7371
// forbidden in HTTP2, as that information has been moved into frame types of the h2
7472
// protocol.
75-
for name in header_contents.split(',') {
76-
let name = name.trim();
77-
headers.remove(name);
73+
if let Ok(header_contents) = header.to_str() {
74+
for name in header_contents.split(',') {
75+
let name = name.trim();
76+
headers.remove(name);
77+
}
7878
}
7979
}
8080
}

0 commit comments

Comments
 (0)