diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-11-11 23:17:12 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-11-13 17:40:59 +0900 |
commit | 76078ad850990fdcd42f82b7add35f73156e35bc (patch) | |
tree | a21cc4d97d8ee8ef18cf7951a994b80fb3f01e08 /src/shared/ask-password-api.c | |
parent | db645f936f2b686e05524e198df00112acaff3c6 (diff) | |
download | systemd-76078ad850990fdcd42f82b7add35f73156e35bc.tar.gz |
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.
Diffstat (limited to 'src/shared/ask-password-api.c')
-rw-r--r-- | src/shared/ask-password-api.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index e0488ff194..e7db23c201 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -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; |