Skip to content

Commit a95c4c9

Browse files
author
Marcin Radomski
committed
tls: don't log nullbytes from log_ssl_error
The function was always logging a 1024 byte long buffer padded with nullbytes. This doesn't look intentional, and may cause trouble for some logger implementations that don't expect nulls in &str. See also: rust-mobile/android_logger-rs#90
1 parent d0efd2c commit a95c4c9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

quiche/src/tls/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,14 @@ fn log_ssl_error() {
10441044
ERR_error_string_n(e, err.as_mut_ptr() as *mut c_char, err.len());
10451045
}
10461046

1047-
trace!("{}", std::str::from_utf8(&err).unwrap());
1047+
let cstr = CStr::from_bytes_until_nul(err.as_mut_ptr())
1048+
.expect("ERR_error_string_n should write a null terminated string");
1049+
1050+
trace!(
1051+
"{}",
1052+
cstr.to_str()
1053+
.expect("ERR_error_string_n should create a valid UTF-8 message")
1054+
);
10481055
}
10491056

10501057
extern "C" {

0 commit comments

Comments
 (0)