mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
recovery-key: add some extra asserts
Let's ensure our key sizes calculations are correct. This doesn't actually change anything, just adds more safety checks. Inspired by #19203, but not a fix.
This commit is contained in:
parent
da846b3031
commit
ff2cf6f8fe
@ -74,6 +74,7 @@ int normalize_recovery_key(const char *password, char **ret) {
|
||||
int make_recovery_key(char **ret) {
|
||||
_cleanup_(erase_and_freep) char *formatted = NULL;
|
||||
_cleanup_(erase_and_freep) uint8_t *key = NULL;
|
||||
size_t j = 0;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@ -91,7 +92,7 @@ int make_recovery_key(char **ret) {
|
||||
if (!formatted)
|
||||
return -ENOMEM;
|
||||
|
||||
for (size_t i = 0, j = 0; i < RECOVERY_KEY_MODHEX_RAW_LENGTH; i++) {
|
||||
for (size_t i = 0; i < RECOVERY_KEY_MODHEX_RAW_LENGTH; i++) {
|
||||
formatted[j++] = modhex_alphabet[key[i] >> 4];
|
||||
formatted[j++] = modhex_alphabet[key[i] & 0xF];
|
||||
|
||||
@ -99,7 +100,9 @@ int make_recovery_key(char **ret) {
|
||||
formatted[j++] = '-';
|
||||
}
|
||||
|
||||
formatted[RECOVERY_KEY_MODHEX_FORMATTED_LENGTH-1] = 0;
|
||||
assert(j == RECOVERY_KEY_MODHEX_FORMATTED_LENGTH);
|
||||
assert(formatted[RECOVERY_KEY_MODHEX_FORMATTED_LENGTH-1] == '-');
|
||||
formatted[RECOVERY_KEY_MODHEX_FORMATTED_LENGTH-1] = 0; /* replace final dash with a NUL */
|
||||
|
||||
*ret = TAKE_PTR(formatted);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user