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/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c | |
parent | hexdecoct: modernize base64mem() variable naming a bit (diff) | |
download | systemd-5e476b851251dd5addd39f06ebdf05bb3efb0be7.tar.xz systemd-5e476b851251dd5addd39f06ebdf05bb3efb0be7.zip |
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/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c')
-rw-r--r-- | src/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c b/src/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c index 2e0450aa5b..1ed9e2bb86 100644 --- a/src/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c +++ b/src/cryptsetup/cryptsetup-tokens/luks2-pkcs11.c @@ -187,6 +187,7 @@ int acquire_luks2_key( _cleanup_free_ char *pkcs11_uri = NULL; _cleanup_free_ void *encrypted_key = NULL; systemd_pkcs11_plugin_params *pkcs11_params = userdata; + ssize_t base64_encoded_size; assert(json); assert(ret_password); @@ -213,12 +214,12 @@ int acquire_luks2_key( if (r < 0) return r; - r = base64mem(decrypted_key, decrypted_key_size, &base64_encoded); - if (r < 0) - return crypt_log_error_errno(cd, r, "Can not base64 encode key: %m"); + base64_encoded_size = base64mem(decrypted_key, decrypted_key_size, &base64_encoded); + if (base64_encoded_size < 0) + return crypt_log_error_errno(cd, (int) base64_encoded_size, "Can not base64 encode key: %m"); *ret_password = TAKE_PTR(base64_encoded); - *ret_password_size = strlen(*ret_password); + *ret_password_size = base64_encoded_size; return 0; } |