Error handling improvement thanks to Erik Edin.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@28 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Clemens Fruhwirth
2008-08-20 10:40:45 +00:00
parent 643aed1891
commit 4884064723
5 changed files with 12 additions and 171 deletions

View File

@@ -50,6 +50,7 @@ static inline int round_up_modulo(int x, int m) {
struct luks_masterkey *LUKS_alloc_masterkey(int keylength)
{
struct luks_masterkey *mk=malloc(sizeof(*mk) + keylength);
if(NULL == mk) return NULL;
mk->keyLength=keylength;
return mk;
}
@@ -66,7 +67,13 @@ void LUKS_dealloc_masterkey(struct luks_masterkey *mk)
struct luks_masterkey *LUKS_generate_masterkey(int keylength)
{
struct luks_masterkey *mk=LUKS_alloc_masterkey(keylength);
getRandom(mk->key,keylength);
if(NULL == mk) return NULL;
int r = getRandom(mk->key,keylength);
if(r < 0) {
LUKS_dealloc_masterkey(mk);
return NULL;
}
return mk;
}