Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

strlcpy() always returns the length of the src str, even if it does not fit and gets truncated with a NULL. My hunch is strncpy() and strlcpy() calls were replaced with strlcpy() calls and whatever code where was before to potentially handle the not fitting and not adding a NULL was removed. Then no code was added after to verify it fit. Imagine it just incremented dst by the return value and then called strlcpy() with the next src str to glue together...

EDIT: Or there is no NULL in src and it runs off into an unmapped page calculating the len :D Wow it's just a pretty bad idea for a lot of cases the more I think about it.



Well, that's a problem of those who replaced that code without handling that change properly, not of strlcpy per se.


And that's what Linus was saying, I was replying to how could someone use strlcpy() dangerously after I mulled it over some.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: