Skip to content

Use strnlen when checking for null byte #1601

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025

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