]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/: vsnprintf_(), strtcpy(): abort() if size==0
authorAlejandro Colomar <alx@kernel.org>
Fri, 5 Dec 2025 11:15:44 +0000 (12:15 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Fri, 15 May 2026 10:06:49 +0000 (12:06 +0200)
There's nothing better that can be done.

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/sprintf/snprintf.h
lib/string/strcpy/strtcpy.h

index 62be874922024260345e5288c9dbc820f7169ba2..9d373d940169718e10d0caecdb5caefd87fa07d0 100644 (file)
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 
 #include "attr.h"
@@ -50,6 +51,9 @@ vsnprintf_(char *restrict s, ssize_t size, const char *restrict fmt, va_list ap)
 {
        int  len;
 
+       if (size == 0)
+               abort();
+
        len = vsnprintf(s, size, fmt, ap);
        if (len == -1)
                return -1;
index 4b9d34b7229ed65c1a7c4d2c8f84cfcf893fb408..a8c3f865ac745c8e8961d8dfd4ea72e8938b67ec 100644 (file)
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
 
@@ -35,7 +36,7 @@ strtcpy(char *restrict dst, const char *restrict src, size_t dsize)
        size_t  dlen, slen;
 
        if (dsize == 0)
-               return -1;
+               abort();
 
        slen = strnlen(src, dsize);
        trunc = (slen == dsize);