Commit 467728b5 authored by Milan Broz's avatar Milan Broz

Fix keylength = 0 (no key) case.

parent 0c990eb0
......@@ -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;
if (key)
memcpy(&vk->key, key, keylength);
else
crypt_memzero(&vk->key, 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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment