diff options
author | Shawn Willden <swillden@google.com> | 2014-08-09 15:47:05 -0600 |
---|---|---|
committer | Shawn Willden <swillden@google.com> | 2014-08-09 15:47:05 -0600 |
commit | 8d336ae10df66da4c0433f17c2d42e85baea32c5 (patch) | |
tree | 8b565da7dbde2f41aa521ca573b9a3f9a23f109b /serializable.cpp | |
parent | 4db3fbdda292c0c3120dfe160c1b49670aa18600 (diff) | |
download | keymaster-8d336ae10df66da4c0433f17c2d42e85baea32c5.tar.gz |
Change authorization set serialization approach to ensure that 32 vs 64
bit size and alignment differences don't cause problems.
Change-Id: I4a308cfac782161db2f1456adb2d6a56537e61f1
Diffstat (limited to 'serializable.cpp')
-rw-r--r-- | serializable.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/serializable.cpp b/serializable.cpp index c00d913..ccb8d0e 100644 --- a/serializable.cpp +++ b/serializable.cpp @@ -18,6 +18,12 @@ namespace keymaster { +uint8_t* append_to_buf(uint8_t* buf, const uint8_t* end, const void* data, size_t data_len) { + if (buf + data_len <= end) + memcpy(buf, data, data_len); + return buf + data_len; +} + bool copy_from_buf(const uint8_t** buf, const uint8_t* end, void* dest, size_t size) { if (end < *buf + size) return false; @@ -29,11 +35,13 @@ bool copy_from_buf(const uint8_t** buf, const uint8_t* end, void* dest, size_t s bool copy_size_and_data_from_buf(const uint8_t** buf, const uint8_t* end, size_t* size, uint8_t** dest) { uint32_t data_len; - if (!copy_from_buf(buf, end, &data_len)) { + if (!copy_from_buf(buf, end, &data_len) || *buf + data_len > end) { return false; } *size = data_len; *dest = new uint8_t[*size]; + if (*dest == NULL) + return false; return copy_from_buf(buf, end, *dest, *size); } |