diff options
author | Jacob Garber <jgarber1@ualberta.ca> | 2019-06-25 11:59:59 -0600 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-07-23 09:09:32 +0000 |
commit | 768db4f5ca93d4dad1f5104e1a3676c40ad85a55 (patch) | |
tree | c0cb2d6db59fa24ae180b827588b673c0842822c | |
parent | 65fe2948a91529c858fdae23a45408ca06953fcf (diff) | |
download | coreboot-768db4f5ca93d4dad1f5104e1a3676c40ad85a55.tar.xz |
libpayload/libc: Correct strlcat return value
The documented return value for strlcat is horribly wrong, as is the
return value itself. It should not return the number of appended bytes,
but rather the length of the concatenated string. From the man page:
The strlcpy() and strlcat() functions return the total length of the
string they tried to create. For strlcpy() that means the length of
src. For strlcat() that means the initial length of dst plus the
length of src. While this may seem somewhat confusing, it was done
to make truncation detection simple.
This change is more likely to fix existing code than break it, since
anyone who uses the return value of strlcat will almost certainly rely
on the standard behaviour rather than investigate coreboot's source code
to see that we have a quirky version.
Change-Id: I4421305af85bce88d12d6fdc2eea6807ccdcf449
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33787
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r-- | payloads/libpayload/libc/string.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 6c257cbdaa..9a5a1ea4c1 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -249,7 +249,7 @@ char *strncat(char *d, const char *s, size_t n) * @param d The destination string. * @param s The source string. * @param n d will have at most n-1 characters (plus NUL) after invocation. - * @return A pointer to the destination string. + * @return The total length of the concatenated string. */ size_t strlcat(char *d, const char *s, size_t n) { @@ -264,7 +264,7 @@ size_t strlcat(char *d, const char *s, size_t n) p[i] = s[i]; p[i] = '\0'; - return max; + return sl + dl; } /** |