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/cryptenroll/cryptenroll-tpm2.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/cryptenroll/cryptenroll-tpm2.c')
-rw-r--r-- | src/cryptenroll/cryptenroll-tpm2.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cryptenroll/cryptenroll-tpm2.c b/src/cryptenroll/cryptenroll-tpm2.c index 5c902908c4..96d5fc0695 100644 --- a/src/cryptenroll/cryptenroll-tpm2.c +++ b/src/cryptenroll/cryptenroll-tpm2.c @@ -145,6 +145,7 @@ int enroll_tpm2(struct crypt_device *cd, uint16_t pcr_bank, primary_alg; const char *node; _cleanup_(erase_and_freep) char *pin_str = NULL; + ssize_t base64_encoded_size; int r, keyslot; TPM2Flags flags = 0; @@ -230,9 +231,9 @@ int enroll_tpm2(struct crypt_device *cd, } /* let's base64 encode the key to use, for compat with homed (and it's easier to every type it in by keyboard, if that might end up being necessary. */ - r = base64mem(secret, secret_size, &base64_encoded); - if (r < 0) - return log_error_errno(r, "Failed to base64 encode secret key: %m"); + base64_encoded_size = base64mem(secret, secret_size, &base64_encoded); + if (base64_encoded_size < 0) + return log_error_errno(base64_encoded_size, "Failed to base64 encode secret key: %m"); r = cryptsetup_set_minimal_pbkdf(cd); if (r < 0) @@ -244,7 +245,7 @@ int enroll_tpm2(struct crypt_device *cd, volume_key, volume_key_size, base64_encoded, - strlen(base64_encoded)); + base64_encoded_size); if (keyslot < 0) return log_error_errno(keyslot, "Failed to add new TPM2 key to %s: %m", node); |