4 ms·
i havent used C in quite a while but I did not remember strlcpy using strlen, and it seems the linux kernel's implementation differs quite a bit from the openbs
by minusf 4y ago
i havent used C in quite a while but I did not remember strlcpy using strlen, and it seems the linux kernel's implementation differs quite a bit from the openbsd one:
https://elixir.bootlin.com/linux/v5.19.3/source/lib/string.c#L125 https://elixir.bootlin.com/linux/v5.19.3/source/lib/string.c...
https://github.com/openbsd/src/blob/master/lib/libc/string/strlcpy.c https://github.com/openbsd/src/blob/master/lib/libc/string/s...
- qhwudbebd 4y agoThe while (*src++); on line 45 of lib/libc/string/strlcpy.c is an inline implementation of strlen here. It's done solely for the benefit of the return value (src - osrc - 1) but means that it traverses the entire length of src until the first NUL - even if that's gigabytes or wanders out of mapped memory.