2
0

Don't leak internal file on error if mpw_marshal_write file is NULL.

This commit is contained in:
Maarten Billemont 2020-04-04 20:17:14 -04:00
parent b118bc4e9b
commit 24a6781687

View File

@ -695,11 +695,17 @@ const char *mpw_marshal_write(
if (!file)
return NULL;
if (!file->data) {
file->error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't allocate data." };
if (!file_)
mpw_marshal_file_free( &file );
else
file->error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't allocate data." };
return NULL;
}
if (!user->fullName || !strlen( user->fullName )) {
file->error = (MPMarshalError){ MPMarshalErrorMissing, "Missing full name." };
if (!file_)
mpw_marshal_file_free( &file );
else
file->error = (MPMarshalError){ MPMarshalErrorMissing, "Missing full name." };
return NULL;
}
file->error = (MPMarshalError){ MPMarshalSuccess, NULL };
@ -740,7 +746,10 @@ const char *mpw_marshal_write(
// Clear Text
mpw_free( &masterKey, MPMasterKeySize );
if (!user->masterKeyProvider || !(masterKey = user->masterKeyProvider( site->algorithm, user->fullName ))) {
file->error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't derive master key." };
if (!file_)
mpw_marshal_file_free( &file );
else
file->error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't derive master key." };
return NULL;
}