WIP: Replace dangerous old string functions with less horrible variants, for -fbounds-safety compatibility - #24
Draft
seanm wants to merge 2 commits into
Draft
Conversation
The old functions can easily overflow buffers but also they are not allowed under -fbounds-safety at all. Most cases were trivial. strncpy() notably zeros the whole buffer, while strlcpy() does not. I examined each case carefully and in most cases calloc() was used previously meaning the buffer was already zeroed. In one case, added a memset(0) to preserve the behaviour, those I'm not sure it really is necessary. In a few cases, too the opportunity to better move variable declaration to first usage or otherwise refactor a little bit.
strlcpy and strlcat came from OpenBSD and have since been added to other BSDs, macOS (and variants), and glibc (though only since 2.38). Add implementations for other platforms.
seanm
marked this pull request as draft
July 31, 2026 19:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@hjmjohnson this one needs careful checking.
Also it's not done yet, I have to do some cmake stuff to compile the new file.