Skip to content

Use strnlen when checking for null byte#1601

Merged
bakpakin merged 1 commit intojanet-lang:masterfrom
edsrzf:limit-buffer-read
Jun 14, 2025
Merged

Use strnlen when checking for null byte#1601
bakpakin merged 1 commit intojanet-lang:masterfrom
edsrzf:limit-buffer-read

Conversation

@edsrzf
Copy link
Contributor

@edsrzf edsrzf commented Jun 14, 2025

Buffers are not always null-terminated, so using strlen here could cause reads past the end of the buffer and cause Janet to incorrectly report that the string contains zeros because the lengths don't match.

There may be other instances to fix, but this fixes #1600.

@bakpakin
Copy link
Member

Looks good. Most places where we convert buffers to strings, we should be calling janet_getcbytes or similar to ensure that final 0 byte of padding.

@bakpakin bakpakin merged commit f181948 into janet-lang:master Jun 14, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"string contains zeros" when formatting buffer

2 participants