mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 10:50:01 +01:00
Fix keylength = 0 (no key) case.
This commit is contained in:
@@ -29,7 +29,7 @@ struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key)
|
||||
{
|
||||
struct volume_key *vk;
|
||||
|
||||
if (!keylength || keylength > (SIZE_MAX - sizeof(*vk)))
|
||||
if (keylength > (SIZE_MAX - sizeof(*vk)))
|
||||
return NULL;
|
||||
|
||||
vk = malloc(sizeof(*vk) + keylength);
|
||||
@@ -37,10 +37,14 @@ struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key)
|
||||
return NULL;
|
||||
|
||||
vk->keylength = keylength;
|
||||
|
||||
/* keylength 0 is valid => no key */
|
||||
if (vk->keylength) {
|
||||
if (key)
|
||||
memcpy(&vk->key, key, keylength);
|
||||
else
|
||||
crypt_memzero(&vk->key, keylength);
|
||||
}
|
||||
|
||||
return vk;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user