mirror of
https://xff.cz/git/u-boot/
synced 2025-10-09 12:06:41 +02:00
Revert "lib: string: Fix strlcpy return value", fix callers
Both the Linux kernel and libbsd agree that strlcpy() should always return strlen(src) and not include the NUL termination. The incorrect U-Boot implementation makes it impossible to check the return value for truncation, and breaks code written with the usual implementation in mind (for example, fdtdec_add_reserved_memory() was subtly broken). I reviewed all callers of strlcpy() and strlcat() and fixed them according to my understanding of the intended function. This reverts commitd3358ecc54
and adds related fixes. Fixes:d3358ecc54
("lib: string: Fix strlcpy return value") Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Sean Anderson <sean.anderson@seco.com>
This commit is contained in:
committed by
Tom Rini
parent
a169438411
commit
615828721a
@@ -43,11 +43,11 @@ static int do_test_strlcat(struct unit_test_state *uts, int line, size_t align1,
|
||||
s2[i] = 32 + 23 * i % (127 - 32);
|
||||
s2[len2 - 1] = '\0';
|
||||
|
||||
expected = len2 < n ? min(len1 + len2 - 1, n) : n;
|
||||
expected = min(strlen(s2), n) + strlen(s1);
|
||||
actual = strlcat(s2, s1, n);
|
||||
if (expected != actual) {
|
||||
ut_failf(uts, __FILE__, line, __func__,
|
||||
"strlcat(s2, s1, 2) == len2 < n ? min(len1 + len2, n) : n",
|
||||
"strlcat(s2, s1, n) == min(len2, n) + len1",
|
||||
"Expected %#zx (%zd), got %#zx (%zd)",
|
||||
expected, expected, actual, actual);
|
||||
return CMD_RET_FAILURE;
|
||||
|
Reference in New Issue
Block a user