summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-07-17 15:25:01 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-07-17 15:34:57 -0400
commitb60df13b39c0237f9cb1114076464d2431e6bee5 (patch)
tree3eebb325b99c3a2010ffd694b91312fdd7a6e9ec /src/shared
parentf41794d0360b8e3a705db58df14957ceb37c6f27 (diff)
basic/strv: add an extra NUL after strings in strv_make_nulstr
strv_make_nulstr was creating a nulstr which was not a valid nulstr, because it was missing the terminating NUL. This didn't cause any issues, because strv_parse_nulstr correctly parsed the result, using the separately specified length. But it's confusing to have something called nulstr which really isn't. It is likely that somebody will try to use strv_make_nulstr() in some other place, incorrectly. This patch changes strv_parse_nulstr() to produce a valid nulstr, and changes the output length parameter to be the minimum number of bytes which can be later on parsed by strv_parse_nulstr(). This allows the only user in ask-password-api to be slightly simplified. Based-on-patch-by: Jean-Sébastien Bour <jean-sebastien@bour.name> Fixes #3689.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ask-password-api.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index a86b0db554..65151b19a6 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -139,11 +139,7 @@ static int add_to_keyring(const char *keyname, AskPasswordFlags flags, char **pa
if (r < 0)
return r;
- /* Truncate trailing NUL */
- assert(n > 0);
- assert(p[n-1] == 0);
-
- serial = add_key("user", keyname, p, n-1, KEY_SPEC_USER_KEYRING);
+ serial = add_key("user", keyname, p, n, KEY_SPEC_USER_KEYRING);
memory_erase(p, n);
if (serial == -1)
return -errno;