nulstr-util: fix corner cases of strv_make_nulstr()
Let's change the return semantics of strv_make_nulstr() so that we can properly distuingish the case where we have a no entries in the nulstr from the case where we have a single empty string in a nulstr. Previously we couldn't distuingish those, we'd in both cases return a size of zero, and a buffer with two NUL bytes. With this change, we'll still return a buffer with two NULL bytes, but for the case where no entries are defined we'll return a size of zero, and where we have two a size of one. This is a good idea, as it makes sure we can properly handle all corner cases. Nowadays the function is used by one place only: ask-password-api.c. The corner case never mattered there, since it was used to serialize passwords, and it was known that there was exactly one password, not less. But let's clean this up. This means the subtraction of the final NUL byte now happens in ask-password-api.c instead.
This commit is contained in:
committed by
Yu Watanabe
parent
db645f936f
commit
76078ad850
@@ -113,6 +113,10 @@ static int add_to_keyring(const char *keyname, AskPasswordFlags flags, char **pa
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* chop off the final NUL byte. We do this because we want to use the separator NUL bytes only if we
|
||||
* have multiple passwords. */
|
||||
n = LESS_BY(n, (size_t) 1);
|
||||
|
||||
serial = add_key("user", keyname, p, n, KEY_SPEC_USER_KEYRING);
|
||||
if (serial == -1)
|
||||
return -errno;
|
||||
|
||||
Reference in New Issue
Block a user