Blame SOURCES/0079-strv-Make-sure-strv_make_nulstr-always-returns-a-val.patch
|
|
ac3a84 |
From c59555a86d3fcd2b8d644885134e19fe864251e5 Mon Sep 17 00:00:00 2001
|
|
|
ac3a84 |
From: Daan De Meyer <daan.j.demeyer@gmail.com>
|
|
|
ac3a84 |
Date: Fri, 11 Nov 2022 11:26:54 +0100
|
|
|
ac3a84 |
Subject: [PATCH] strv: Make sure strv_make_nulstr() always returns a valid
|
|
|
ac3a84 |
nulstr
|
|
|
ac3a84 |
|
|
|
ac3a84 |
strv_make_nulstr() is documented to always return a valid nulstr,
|
|
|
ac3a84 |
but if the input is `NULL` we return a string terminated with only
|
|
|
ac3a84 |
a single NUL terminator, so let's fix that and always terminate the
|
|
|
ac3a84 |
resulting string with two NUL bytes.
|
|
|
ac3a84 |
|
|
|
ac3a84 |
(cherry picked from commit 5ea173a91b2093664a9ebb9add678edd6f5d1efd)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
Related: #2138081
|
|
|
ac3a84 |
---
|
|
|
ac3a84 |
src/basic/strv.c | 6 ++----
|
|
|
ac3a84 |
1 file changed, 2 insertions(+), 4 deletions(-)
|
|
|
ac3a84 |
|
|
|
ac3a84 |
diff --git a/src/basic/strv.c b/src/basic/strv.c
|
|
|
ac3a84 |
index eea34ca68d..24fc56a1a5 100644
|
|
|
ac3a84 |
--- a/src/basic/strv.c
|
|
|
ac3a84 |
+++ b/src/basic/strv.c
|
|
|
ac3a84 |
@@ -721,7 +721,7 @@ int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|
|
|
ac3a84 |
if (!m) {
|
|
|
ac3a84 |
- m = new0(char, 1);
|
|
|
ac3a84 |
+ m = new0(char, 2);
|
|
|
ac3a84 |
if (!m)
|
|
|
ac3a84 |
return -ENOMEM;
|
|
|
ac3a84 |
n = 1;
|
|
|
ac3a84 |
@@ -730,11 +730,9 @@ int strv_make_nulstr(char * const *l, char **ret, size_t *ret_size) {
|
|
|
ac3a84 |
m[n] = '\0';
|
|
|
ac3a84 |
|
|
|
ac3a84 |
assert(n > 0);
|
|
|
ac3a84 |
- *ret = m;
|
|
|
ac3a84 |
+ *ret = TAKE_PTR(m);
|
|
|
ac3a84 |
*ret_size = n - 1;
|
|
|
ac3a84 |
|
|
|
ac3a84 |
- m = NULL;
|
|
|
ac3a84 |
-
|
|
|
ac3a84 |
return 0;
|
|
|
ac3a84 |
}
|
|
|
ac3a84 |
|