Fix keyslots size overflow when device too small.

It properly failed but debug message was confusing.
Now it fails later properly with "device too small"
error message.
This commit is contained in:
Ondrej Kozina
2021-02-23 11:28:03 +01:00
parent 6a8bade7e6
commit 6e6e9f169e

View File

@@ -247,7 +247,8 @@ int LUKS2_generate_hdr(
/* Decrease keyslots_size due to metadata device being too small */
if (!device_size(crypt_metadata_device(cd), &mdev_size) &&
((keyslots_size + get_min_offset(hdr)) > mdev_size) &&
device_fallocate(crypt_metadata_device(cd), keyslots_size + get_min_offset(hdr)))
device_fallocate(crypt_metadata_device(cd), keyslots_size + get_min_offset(hdr)) &&
(get_min_offset(hdr) <= mdev_size))
keyslots_size = mdev_size - get_min_offset(hdr);
}