Skip to content

Avoid panic on buffers with embedded nul bytes #90

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dextero
Copy link

@dextero dextero commented Mar 18, 2025

Some crates use log crate with a message padded with a number of nullbytes [1]. This currently causes panics.

Using CStr::from_bytes_until_nul accepts multiple null-bytes, and instead stops at the first nullbyte in a buffer.

This may truncate some logs with text interspersed with nullbytes. However, I'd say logging something there is a less-bad option than crashing just because we got a nullbyte in the &str.

[1] https://github.com/cloudflare/quiche/blob/d0efd2c5278b9dbe8d6544c3015f8c772f3513b4/quiche/src/tls/mod.rs#L1040

Some crates use log crate with a message padded with a number of
nullbytes [1]. This currently causes panics.

Using `CStr::from_bytes_until_nul` accepts multiple null-bytes, and
instead stops at the first nullbyte in a buffer.

This may truncate some logs with text interspersed with nullbytes.
However, I'd say logging _something_ there is a less-bad option than
crashing just because we got a nullbyte in the &str.

[1] https://github.com/cloudflare/quiche/blob/d0efd2c5278b9dbe8d6544c3015f8c772f3513b4/quiche/src/tls/mod.rs#L1040
Instead of truncating the message in output_specified_len. This way
output_specified_len still outputs specified len of bytes, while not
crashing if someone feels daring enough to log nulls.
dextero pushed a commit to dextero/quiche that referenced this pull request Mar 19, 2025
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
dextero pushed a commit to dextero/quiche that referenced this pull request Mar 19, 2025
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
ghedo pushed a commit to cloudflare/quiche that referenced this pull request Mar 27, 2025
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants