Commit b70e0b06 authored by Denis Kasak's avatar Denis Kasak Committed by Hubert Chathi
Browse files

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.
parent d704f4bd
Pipeline #8714 passed with stages
in 2 minutes and 25 seconds
...@@ -58,6 +58,12 @@ enum OlmErrorCode { ...@@ -58,6 +58,12 @@ enum OlmErrorCode {
*/ */
OLM_SAS_THEIR_KEY_NOT_SET = 16, 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 /* remember to update the list of string constants in error.c when updating
* this list. */ * this list. */
}; };
......
...@@ -32,7 +32,8 @@ static const char * ERRORS[] = { ...@@ -32,7 +32,8 @@ static const char * ERRORS[] = {
"BAD_LEGACY_ACCOUNT_PICKLE", "BAD_LEGACY_ACCOUNT_PICKLE",
"BAD_SIGNATURE", "BAD_SIGNATURE",
"OLM_INPUT_BUFFER_TOO_SMALL", "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) const char * _olm_error_to_string(enum OlmErrorCode error)
......
...@@ -275,7 +275,7 @@ size_t olm_unpickle_inbound_group_session( ...@@ -275,7 +275,7 @@ size_t olm_unpickle_inbound_group_session(
if (pos != end) { if (pos != end) {
/* Input was longer than expected. */ /* Input was longer than expected. */
session->last_error = OLM_CORRUPTED_PICKLE; session->last_error = OLM_PICKLE_EXTRA_DATA;
return (size_t)-1; return (size_t)-1;
} }
......
...@@ -303,7 +303,7 @@ size_t olm_unpickle_account( ...@@ -303,7 +303,7 @@ size_t olm_unpickle_account(
return std::size_t(-1); return std::size_t(-1);
} else if (pos != end) { } else if (pos != end) {
/* Input was longer than expected. */ /* 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); return std::size_t(-1);
} }
...@@ -338,7 +338,7 @@ size_t olm_unpickle_session( ...@@ -338,7 +338,7 @@ size_t olm_unpickle_session(
return std::size_t(-1); return std::size_t(-1);
} else if (pos != end) { } else if (pos != end) {
/* Input was longer than expected. */ /* 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); return std::size_t(-1);
} }
......
...@@ -160,7 +160,7 @@ size_t olm_unpickle_outbound_group_session( ...@@ -160,7 +160,7 @@ size_t olm_unpickle_outbound_group_session(
if (pos != end) { if (pos != end) {
/* Input was longer than expected. */ /* Input was longer than expected. */
session->last_error = OLM_CORRUPTED_PICKLE; session->last_error = OLM_PICKLE_EXTRA_DATA;
return (size_t)-1; return (size_t)-1;
} }
......
...@@ -348,7 +348,7 @@ size_t olm_unpickle_pk_decryption( ...@@ -348,7 +348,7 @@ size_t olm_unpickle_pk_decryption(
return std::size_t(-1); return std::size_t(-1);
} else if (pos != end) { } else if (pos != end) {
/* Input was longer than expected. */ /* 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); return std::size_t(-1);
} }
......
...@@ -73,7 +73,7 @@ int main() { ...@@ -73,7 +73,7 @@ int main() {
"secret_key", 10, "secret_key", 10,
junk_pickle.data(), junk_pickle_length 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)); olm_outbound_group_session_last_error_code(session));
} }
...@@ -128,7 +128,7 @@ int main() { ...@@ -128,7 +128,7 @@ int main() {
"secret_key", 10, "secret_key", 10,
junk_pickle.data(), junk_pickle_length 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)); olm_inbound_group_session_last_error_code(session));
} }
......
...@@ -83,7 +83,7 @@ const size_t junk_pickle_length = add_junk_suffix_to_pickle( ...@@ -83,7 +83,7 @@ const size_t junk_pickle_length = add_junk_suffix_to_pickle(
assert_equals(std::size_t(-1), assert_equals(std::size_t(-1),
::olm_unpickle_account(account, "secret_key", 10, ::olm_unpickle_account(account, "secret_key", 10,
junk_pickle.data(), junk_pickle_length)); 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( ...@@ -174,7 +174,7 @@ const size_t junk_pickle_length = add_junk_suffix_to_pickle(
assert_equals(std::size_t(-1), assert_equals(std::size_t(-1),
::olm_unpickle_session(session, "secret_key", 10, ::olm_unpickle_session(session, "secret_key", 10,
junk_pickle.data(), junk_pickle_length)); 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 */ { /** Loopback test */
......
...@@ -167,7 +167,7 @@ assert_equals(std::size_t(-1), ...@@ -167,7 +167,7 @@ assert_equals(std::size_t(-1),
junk_pickle.data(), junk_pickle_length, junk_pickle.data(), junk_pickle_length,
pubkey.data(), pubkey.size() 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"); char *ciphertext = strdup("ntk49j/KozVFtSqJXhCejg");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment