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;
|
struct volume_key *vk;
|
||||||
|
|
||||||
if (!keylength || keylength > (SIZE_MAX - sizeof(*vk)))
|
if (keylength > (SIZE_MAX - sizeof(*vk)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
vk = malloc(sizeof(*vk) + keylength);
|
vk = malloc(sizeof(*vk) + keylength);
|
||||||
@@ -37,10 +37,14 @@ struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
vk->keylength = keylength;
|
vk->keylength = keylength;
|
||||||
if (key)
|
|
||||||
memcpy(&vk->key, key, keylength);
|
/* keylength 0 is valid => no key */
|
||||||
else
|
if (vk->keylength) {
|
||||||
crypt_memzero(&vk->key, keylength);
|
if (key)
|
||||||
|
memcpy(&vk->key, key, keylength);
|
||||||
|
else
|
||||||
|
crypt_memzero(&vk->key, keylength);
|
||||||
|
}
|
||||||
|
|
||||||
return vk;
|
return vk;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user