diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-11 10:42:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-11 10:46:08 +0100 |
commit | 5e476b851251dd5addd39f06ebdf05bb3efb0be7 (patch) | |
tree | 8ba503245922f61e74e146fb0dbbbb2f9f0baf8f /src/home/homectl-pkcs11.c | |
parent | a71e17f3e0f872b4264520ac6c4f9312b5312050 (diff) | |
download | systemd-5e476b851251dd5addd39f06ebdf05bb3efb0be7.tar.gz |
tree-wide: fix return value handling of base64mem()
This returns an ssize_t, not an int. On populare archs that's the
difference between 64bit and 32bit. hence, let's be more careful here,
and not silently drop half the bits on the ground by assigning the
return value to "int".
As noticed by @malikabhi05:
https://github.com/systemd/systemd/pull/24754#discussion_r1062903159
Diffstat (limited to 'src/home/homectl-pkcs11.c')
-rw-r--r-- | src/home/homectl-pkcs11.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/home/homectl-pkcs11.c b/src/home/homectl-pkcs11.c index 69c9d97aca..dc6ecf1665 100644 --- a/src/home/homectl-pkcs11.c +++ b/src/home/homectl-pkcs11.c @@ -19,6 +19,7 @@ static int add_pkcs11_encrypted_key( _cleanup_(json_variant_unrefp) JsonVariant *l = NULL, *w = NULL, *e = NULL; _cleanup_(erase_and_freep) char *base64_encoded = NULL, *hashed = NULL; + ssize_t base64_encoded_size; int r; assert(v); @@ -30,9 +31,9 @@ static int add_pkcs11_encrypted_key( /* Before using UNIX hashing on the supplied key we base64 encode it, since crypt_r() and friends * expect a NUL terminated string, and we use a binary key */ - r = base64mem(decrypted_key, decrypted_key_size, &base64_encoded); - if (r < 0) - return log_error_errno(r, "Failed to base64 encode secret key: %m"); + base64_encoded_size = base64mem(decrypted_key, decrypted_key_size, &base64_encoded); + if (base64_encoded_size < 0) + return log_error_errno(base64_encoded_size, "Failed to base64 encode secret key: %m"); r = hash_password(base64_encoded, &hashed); if (r < 0) |