Skip to content

Fix size calculation in my_strlcat#3500

Merged
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:haha
Feb 12, 2026
Merged

Fix size calculation in my_strlcat#3500
ptitSeb merged 1 commit intoptitSeb:mainfrom
devarajabc:haha

Conversation

@devarajabc
Copy link
Copy Markdown
Contributor

strncat was called with the total buffer size, ignoring the length of the existing string in 'dst'. This caused a buffer overflow when appending to a non-empty string.

Fixed by passing 'remaining space' (total - current - 1) to strncat:
strncat(dst, src, l-s-1); // Remaining space in buffer

Also fix strlcpy off-by-one buffer overflow:
dest[len-1]=0; // Write NUL within buffer bounds

Previously, strncat was called with the total buffer size, ignoring the
length of the existing string in 'dst'. This caused a buffer overflow
when appending to a non-empty string.

Fixed by passing 'remaining space' (total - current - 1) to strncat:
strncat(dst, src, l-s-1);   // Remaining space in buffer

Also fix strlcpy off-by-one buffer overflow:
dest[len-1]=0;   // Write NUL within buffer bounds
@ptitSeb ptitSeb merged commit d7f4176 into ptitSeb:main Feb 12, 2026
27 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.

2 participants