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