From 68e58cddd448883dfeecd1fdaa519653c1e2b6db Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Mon, 13 May 2019 11:23:43 -0400 Subject: [PATCH] Fix loading user from flat format without sites. --- platform-independent/c/core/src/mpw-marshal.c | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/platform-independent/c/core/src/mpw-marshal.c b/platform-independent/c/core/src/mpw-marshal.c index 38eaf478..9da389a0 100644 --- a/platform-independent/c/core/src/mpw-marshal.c +++ b/platform-independent/c/core/src/mpw-marshal.c @@ -444,6 +444,22 @@ static MPMarshalledUser *mpw_marshal_read_flat( if (*positionInLine == '#') { // ## ends header headerEnded = true; + mpw_free( &masterKey, MPMasterKeySize ); + if (!(masterKey = masterKeyProvider( algorithm, fullName ))) { + *error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't derive master key." }; + return NULL; + } + if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) { + *error = (MPMarshalError){ MPMarshalErrorMasterPassword, "Master password doesn't match key ID." }; + return NULL; + } + if (!user && !(user = mpw_marshal_user( fullName, masterKeyProvider, algorithm ))) { + *error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't allocate a new user." }; + return NULL; + } + user->redacted = importRedacted; + user->avatar = avatar; + user->defaultType = defaultType; continue; } @@ -495,26 +511,6 @@ static MPMarshalledUser *mpw_marshal_read_flat( if (positionInLine >= endOfLine) continue; - if (!user) { - mpw_free( &masterKey, MPMasterKeySize ); - if (!(masterKey = masterKeyProvider( algorithm, fullName ))) { - *error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't derive master key." }; - return NULL; - } - if (keyID && !mpw_id_buf_equals( keyID, mpw_id_buf( masterKey, MPMasterKeySize ) )) { - *error = (MPMarshalError){ MPMarshalErrorMasterPassword, "Master password doesn't match key ID." }; - return NULL; - } - if (!(user = mpw_marshal_user( fullName, masterKeyProvider, algorithm ))) { - *error = (MPMarshalError){ MPMarshalErrorInternal, "Couldn't allocate a new user." }; - return NULL; - } - - user->redacted = importRedacted; - user->avatar = avatar; - user->defaultType = defaultType; - } - // Site char *siteLoginName = NULL, *siteName = NULL, *siteContent = NULL; char *str_lastUsed = NULL, *str_uses = NULL, *str_type = NULL, *str_algorithm = NULL, *str_counter = NULL;