Differentiate between malformed pickle objects and trailing junk data.
Adds the OLM_PICKLE_EXTRA_DATA error code. We fail with this code when the pickle object looks right except for some unexpected trailing bytes which we didn't process.
This commit is contained in:
parent
d704f4bd3c
commit
b70e0b06df
9 changed files with 18 additions and 11 deletions
|
@ -58,6 +58,12 @@ enum OlmErrorCode {
|
|||
*/
|
||||
OLM_SAS_THEIR_KEY_NOT_SET = 16,
|
||||
|
||||
/**
|
||||
* The pickled object was successfully decoded, but the unpickling still failed
|
||||
* because it had some extraneous junk data at the end.
|
||||
*/
|
||||
OLM_PICKLE_EXTRA_DATA = 17,
|
||||
|
||||
/* remember to update the list of string constants in error.c when updating
|
||||
* this list. */
|
||||
};
|
||||
|
|
|
@ -32,7 +32,8 @@ static const char * ERRORS[] = {
|
|||
"BAD_LEGACY_ACCOUNT_PICKLE",
|
||||
"BAD_SIGNATURE",
|
||||
"OLM_INPUT_BUFFER_TOO_SMALL",
|
||||
"OLM_SAS_THEIR_KEY_NOT_SET"
|
||||
"OLM_SAS_THEIR_KEY_NOT_SET",
|
||||
"OLM_PICKLE_EXTRA_DATA"
|
||||
};
|
||||
|
||||
const char * _olm_error_to_string(enum OlmErrorCode error)
|
||||
|
|
|
@ -275,7 +275,7 @@ size_t olm_unpickle_inbound_group_session(
|
|||
|
||||
if (pos != end) {
|
||||
/* Input was longer than expected. */
|
||||
session->last_error = OLM_CORRUPTED_PICKLE;
|
||||
session->last_error = OLM_PICKLE_EXTRA_DATA;
|
||||
return (size_t)-1;
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ size_t olm_unpickle_account(
|
|||
return std::size_t(-1);
|
||||
} else if (pos != end) {
|
||||
/* Input was longer than expected. */
|
||||
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
||||
object.last_error = OlmErrorCode::OLM_PICKLE_EXTRA_DATA;
|
||||
return std::size_t(-1);
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ size_t olm_unpickle_session(
|
|||
return std::size_t(-1);
|
||||
} else if (pos != end) {
|
||||
/* Input was longer than expected. */
|
||||
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
||||
object.last_error = OlmErrorCode::OLM_PICKLE_EXTRA_DATA;
|
||||
return std::size_t(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ size_t olm_unpickle_outbound_group_session(
|
|||
|
||||
if (pos != end) {
|
||||
/* Input was longer than expected. */
|
||||
session->last_error = OLM_CORRUPTED_PICKLE;
|
||||
session->last_error = OLM_PICKLE_EXTRA_DATA;
|
||||
return (size_t)-1;
|
||||
}
|
||||
|
||||
|
|
|
@ -348,7 +348,7 @@ size_t olm_unpickle_pk_decryption(
|
|||
return std::size_t(-1);
|
||||
} else if (pos != end) {
|
||||
/* Input was longer than expected. */
|
||||
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
||||
object.last_error = OlmErrorCode::OLM_PICKLE_EXTRA_DATA;
|
||||
return std::size_t(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ int main() {
|
|||
"secret_key", 10,
|
||||
junk_pickle.data(), junk_pickle_length
|
||||
));
|
||||
assert_equals(OLM_CORRUPTED_PICKLE,
|
||||
assert_equals(OLM_PICKLE_EXTRA_DATA,
|
||||
olm_outbound_group_session_last_error_code(session));
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ int main() {
|
|||
"secret_key", 10,
|
||||
junk_pickle.data(), junk_pickle_length
|
||||
));
|
||||
assert_equals(OLM_CORRUPTED_PICKLE,
|
||||
assert_equals(OLM_PICKLE_EXTRA_DATA,
|
||||
olm_inbound_group_session_last_error_code(session));
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ const size_t junk_pickle_length = add_junk_suffix_to_pickle(
|
|||
assert_equals(std::size_t(-1),
|
||||
::olm_unpickle_account(account, "secret_key", 10,
|
||||
junk_pickle.data(), junk_pickle_length));
|
||||
assert_equals(OLM_CORRUPTED_PICKLE, olm_account_last_error_code(account));
|
||||
assert_equals(OLM_PICKLE_EXTRA_DATA, olm_account_last_error_code(account));
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,7 +174,7 @@ const size_t junk_pickle_length = add_junk_suffix_to_pickle(
|
|||
assert_equals(std::size_t(-1),
|
||||
::olm_unpickle_session(session, "secret_key", 10,
|
||||
junk_pickle.data(), junk_pickle_length));
|
||||
assert_equals(OLM_CORRUPTED_PICKLE, olm_session_last_error_code(session));
|
||||
assert_equals(OLM_PICKLE_EXTRA_DATA, olm_session_last_error_code(session));
|
||||
}
|
||||
|
||||
{ /** Loopback test */
|
||||
|
|
|
@ -167,7 +167,7 @@ assert_equals(std::size_t(-1),
|
|||
junk_pickle.data(), junk_pickle_length,
|
||||
pubkey.data(), pubkey.size()
|
||||
));
|
||||
assert_equals(OLM_CORRUPTED_PICKLE, olm_pk_decryption_last_error_code(decryption));
|
||||
assert_equals(OLM_PICKLE_EXTRA_DATA, olm_pk_decryption_last_error_code(decryption));
|
||||
/***/
|
||||
|
||||
char *ciphertext = strdup("ntk49j/KozVFtSqJXhCejg");
|
||||
|
|
Loading…
Reference in a new issue