projects
/
systemd
/
.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
0f3c342
)
strv: Make sure strv_make_nulstr() always returns a valid nulstr
author
Daan De Meyer
<daan.j.demeyer@gmail.com>
Fri, 11 Nov 2022 10:26:54 +0000
(11:26 +0100)
committer
Daan De Meyer
<daan.j.demeyer@gmail.com>
Fri, 11 Nov 2022 15:31:20 +0000
(16:31 +0100)
strv_make_nulstr() is documented to always return a valid nulstr,
but if the input is `NULL` we return a string terminated with only
a single NUL terminator, so let's fix that and always terminate the
resulting string with two NUL bytes.
src/basic/strv.c
patch
|
blob
|
history
diff --git
a/src/basic/strv.c
b/src/basic/strv.c
index eea34ca68d9a98f6317b190b5927f3536c40e7e6..24fc56a1a5cafcfbd53cdfdd92d7a8f4506da57b 100644
(file)
--- a/
src/basic/strv.c
+++ b/
src/basic/strv.c
@@
-721,7
+721,7
@@
int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {
}
if (!m) {
- m = new0(char,
1
);
+ m = new0(char,
2
);
if (!m)
return -ENOMEM;
n = 1;
@@
-730,11
+730,9
@@
int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {
m[n] = '\0';
assert(n > 0);
- *ret =
m
;
+ *ret =
TAKE_PTR(m)
;
*ret_size = n - 1;
- m = NULL;
-
return 0;
}