1
2
Fork
You've already forked str
1

Fix: guard against size == 0 unsigned wraparound in strzcpy #5

Closed
ehatch wants to merge 4 commits from (deleted):fix/strzcpy-size-zero into main
pull from: (deleted):fix/strzcpy-size-zero
merge into: rubiefawn:main
rubiefawn:main
Contributor
Copy link

when size==0 is passed to strzcpy the expression size - 1 wraps around to SIZE_MAX as it is unsigned causing a buffer overflow

test: test.c:26: main: Assertion `rem == -2' failed.
zsh: IOT instruction (core dumped) ./bin/test

add early return for size == 0 to fix this

when size==0 is passed to strzcpy the expression size - 1 wraps around to SIZE_MAX as it is unsigned causing a buffer overflow test: test.c:26: main: Assertion `rem == -2' failed. zsh: IOT instruction (core dumped) ./bin/test add early return for size == 0 to fix this
Fix compatiblity with earlier C standards
All checks were successful
Publish documentation / publish (push) Successful in 24s
2e46425606
- Use NULL rather than C23's nullptr
- Omit _Generic macros when compiling with < C11
- Remove the attributes I just added, attributes are a C23 feature
- Add -std=c17 to the test binary specifically
- Exclude strdup() polyfill when compiling with MSVC
I really like C23, but there's no point in polyfilling C23 features if
C23 is required to use the polyfill lmao
ehatch closed this pull request 2026年05月08日 10:05:27 +02:00
ehatch deleted branch fix/strzcpy-size-zero 2026年05月08日 10:06:14 +02:00

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rubiefawn/str!5
Reference in a new issue
rubiefawn/str
No description provided.
Delete branch "(deleted):fix/strzcpy-size-zero"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?