Skip to content

Commit f0084e1

Browse files
committed
Don't return ASCII control characters in HTTP error messages
1 parent 4f880c6 commit f0084e1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lightning-block-sync/src/http.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,11 @@ impl HttpClient {
348348

349349
if !status.is_ok() {
350350
// TODO: Handle 3xx redirection responses.
351-
let error_details = match contents.is_ascii() {
352-
true => String::from_utf8_lossy(&contents).to_string(),
353-
false => "binary".to_string()
351+
let error_details = match String::from_utf8(contents) {
352+
// Check that the string is all-ASCII with no control characters before returning
353+
// it.
354+
Ok(s) if s.as_bytes().iter().all(|c| c.is_ascii() && !c.is_ascii_control()) => s,
355+
_ => "binary".to_string()
354356
};
355357
let error_msg = format!("Errored with status: {} and contents: {}",
356358
status.code, error_details);

0 commit comments

Comments
 (0)