]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nulstr-util: use memdup_suffix0() where appropriate
authorLennart Poettering <lennart@poettering.net>
Fri, 11 Nov 2022 21:04:37 +0000 (22:04 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Nov 2022 08:39:08 +0000 (17:39 +0900)
if the nulstr is not nul-terminated, we shouldn't use strndup() but
memdup_suffix0(), to not trip up static analyzers which imply we are
duping a string here.

src/basic/nulstr-util.c

index e8e5629e95296215a19b5c607b84a1a1cc82eb73..2da64fcbe9909c18a4e585efcaa72a7e75e7ff61 100644 (file)
@@ -37,7 +37,7 @@ char** strv_parse_nulstr(const char *s, size_t l) {
 
                 e = memchr(p, 0, s + l - p);
 
-                v[i] = strndup(p, e ? e - p : s + l - p);
+                v[i] = memdup_suffix0(p, e ? e - p : s + l - p);
                 if (!v[i])
                         return NULL;