From: Alejandro Colomar Date: Sat, 8 Feb 2025 15:13:39 +0000 (+0100) Subject: lib/string/: vsnprintf_(), strtcpy(): Set errno = E2BIG on truncation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=470cfa23c74694918396e603c78381f27c2be99e;p=thirdparty%2Fshadow.git lib/string/: vsnprintf_(), strtcpy(): Set errno = E2BIG on truncation Signed-off-by: Alejandro Colomar --- diff --git a/lib/string/sprintf/snprintf.h b/lib/string/sprintf/snprintf.h index f6dee1245..dc6009457 100644 --- a/lib/string/sprintf/snprintf.h +++ b/lib/string/sprintf/snprintf.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar +// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar // SPDX-License-Identifier: BSD-3-Clause @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -53,8 +54,10 @@ vsnprintf_(char *restrict s, size_t size, const char *restrict fmt, va_list ap) len = vsnprintf(s, size, fmt, ap); if (len == -1) return -1; - if ((size_t) len >= size) + if ((size_t) len >= size) { + errno = E2BIG; return -1; + } return len; } diff --git a/lib/string/strcpy/strtcpy.h b/lib/string/strcpy/strtcpy.h index a440bcdfb..4b9d34b72 100644 --- a/lib/string/strcpy/strtcpy.h +++ b/lib/string/strcpy/strtcpy.h @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include #include @@ -42,8 +43,10 @@ strtcpy(char *restrict dst, const char *restrict src, size_t dsize) stpcpy(mempcpy(dst, src, dlen), ""); - if (trunc) + if (trunc) { + errno = E2BIG; return -1; + } return slen; }