From 690c22ac7b84baf1e724036bf7ab3f03b5ec3bbd Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 28 Nov 2024 10:41:18 +0100 Subject: [PATCH] Switch isLUKS() testing order to avoid static analysis scan confusion. There is no functional change in this patch except it avoids strange confusion during some static tests. The cd->type must be set in this function anyway. --- lib/setup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/setup.c b/lib/setup.c index 0d694d24..66a034c7 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -4552,7 +4552,13 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd, } keyslot_old = r; - if (isLUKS2(cd->type)) { + if (isLUKS1(cd->type)) { + if (keyslot_new == CRYPT_ANY_SLOT) { + keyslot_new = LUKS_keyslot_find_empty(&cd->u.luks1.hdr); + if (keyslot_new < 0) + keyslot_new = keyslot_old; + } + } else if (isLUKS2(cd->type)) { /* If there is a free keyslot (both id and binary area) avoid in-place keyslot area overwrite */ if (keyslot_new == CRYPT_ANY_SLOT || keyslot_new == keyslot_old) { keyslot_new = LUKS2_keyslot_find_empty(cd, &cd->u.luks2.hdr, vk->keylength); @@ -4561,12 +4567,6 @@ int crypt_keyslot_change_by_passphrase(struct crypt_device *cd, else keyslot_swap = true; } - } else if (isLUKS1(cd->type)) { - if (keyslot_new == CRYPT_ANY_SLOT) { - keyslot_new = LUKS_keyslot_find_empty(&cd->u.luks1.hdr); - if (keyslot_new < 0) - keyslot_new = keyslot_old; - } } log_dbg(cd, "Key change, old slot %d, new slot %d.", keyslot_old, keyslot_new);