6 ms·
> We had similar issues with the completely moronic and misdesigned crap called "strlcpy()", which was introduced for similar reasons, and also caused nasty bug
by shmerl 11y ago
> We had similar issues with the completely moronic and misdesigned crap called "strlcpy()", which was introduced for similar reasons, and also caused nasty bugs where the old code was actually correct, and the "converted to better and safer interfaces" code was actually buggy.
What's wrong with strlcpy? When I need one, I take the code from OpenBSD:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/string/strlcpy.c?rev=1.13&content-type=text/plain http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/...
Reasons for having it are surely not moronic because it provides security benefits.
- vezzy-fnord 11y agostrlcpy(3) is actually used quite heavily throughout the Linux kernel: http://lxr.free-electrons.com/ident?i=strlcpy http://lxr.free-electrons.com/ident?i=strlcpy I'm not sure what Linus intended.
- shmerl 11y agoThough for some reason it still didn't make it into glibc.
- heinrich5991 11y agoThat's because C never has problems with buffer overflows. What's far worse: strlcpy truncates the string in case it wouldn't fit the buffer!
- mzs 11y agoUlrich Drepper was the maintainer of glibc at the time: https://www.sourceware.org/ml/libc-alpha/2000-08/msg00061.html https://www.sourceware.org/ml/libc-alpha/2000-08/msg00061.ht...
- ori_b 11y agoThe kernel developers aren't the glibc developers.
- teacup50 11y agoIt's not strlcpy he had an issue with. His issue was converting a whole lot of code over to strlcpy() while introducing bugs that didn't previously exist. For another example of this kind of irrational thinking, look at NeoVim's massive churning changes to the Vim codebase for the purposes of "modernization".
- justinmk 11y agoWhat changes to Neovim are you referring to? We are generally very careful about "cleanup" patches in Neovim. Some examples: https://github.com/neovim/neovim/pull/2418 https://github.com/neovim/neovim/pull/2418 https://github.com/neovim/neovim/pull/1788 https://github.com/neovim/neovim/pull/1788 https://github.com/neovim/neovim/pull/1340 https://github.com/neovim/neovim/pull/1340 At least one tangible benefit to some of these changes is that it allows us to enable -Wconversion. We've also rejected dozens of cleanup patches for quality reasons.
- deleted 11y ago[deleted]
- shmerl 11y agoI didn't track the style of Neovim changes, but I appreciate them actually making a moving project. vim has bugs and feature requests which aren't fixed for years. I'm using Neovim currently and really enjoy that it supports stuff like 24 bit color schemes in the terminal. I finally can use color schemes which don't hurt my eyes.
- mzs 11y agostrlcpy() 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.