aboutsummaryrefslogtreecommitdiff
path: root/src/session.cpp
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-10 18:00:18 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-10 18:00:18 +0100
commit5ad929104e4db4b788c3792bca3e7d02283dc77e (patch)
treece36f53e86e1c4ac654c65ee630d53a4e45a8a56 /src/session.cpp
parentb6e248c9a58cccbcd5dea7bdc8e3cdee4af03722 (diff)
Version the pickled objects and check for errors when unpickling them
Diffstat (limited to 'src/session.cpp')
-rw-r--r--src/session.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/session.cpp b/src/session.cpp
index 4abf6cf..654cf1f 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -353,11 +353,15 @@ std::size_t olm::Session::decrypt(
return result;
}
+namespace {
+static const std::uint32_t SESSION_PICKLE_VERSION = 1;
+}
std::size_t olm::pickle_length(
Session const & value
) {
std::size_t length = 0;
+ length += olm::pickle_length(SESSION_PICKLE_VERSION);
length += olm::pickle_length(value.received_message);
length += olm::pickle_length(value.alice_identity_key);
length += olm::pickle_length(value.alice_base_key);
@@ -371,6 +375,7 @@ std::uint8_t * olm::pickle(
std::uint8_t * pos,
Session const & value
) {
+ pos = olm::pickle(pos, SESSION_PICKLE_VERSION);
pos = olm::pickle(pos, value.received_message);
pos = olm::pickle(pos, value.alice_identity_key);
pos = olm::pickle(pos, value.alice_base_key);
@@ -384,6 +389,12 @@ std::uint8_t const * olm::unpickle(
std::uint8_t const * pos, std::uint8_t const * end,
Session & value
) {
+ uint32_t pickle_version;
+ pos = olm::unpickle(pos, end, pickle_version);
+ if (pickle_version != SESSION_PICKLE_VERSION) {
+ value.last_error = olm::ErrorCode::UNKNOWN_PICKLE_VERSION;
+ return end;
+ }
pos = olm::unpickle(pos, end, value.received_message);
pos = olm::unpickle(pos, end, value.alice_identity_key);
pos = olm::unpickle(pos, end, value.alice_base_key);