diff options
author | Shawn Willden <swillden@google.com> | 2014-08-25 06:49:54 -0600 |
---|---|---|
committer | Shawn Willden <swillden@google.com> | 2014-08-25 06:49:54 -0600 |
commit | f2282b3c6690ccfaa7878886f01693ef4f0b3bed (patch) | |
tree | 9ae51eb456740ac028e73bbf1a28cfa44b912dbc /serializable.cpp | |
parent | b663b61f00b1a51a2535520aa726f788fffdf34b (diff) | |
download | keymaster-f2282b3c6690ccfaa7878886f01693ef4f0b3bed.tar.gz |
Add some "fuzzing" tests for deserialization, and fixes for all of the
problems discovered.
Change-Id: I050344f6c6d0a19b7f3304d23729b4ca71c05042
Diffstat (limited to 'serializable.cpp')
-rw-r--r-- | serializable.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/serializable.cpp b/serializable.cpp index 8b35d4b..ddac8f1 100644 --- a/serializable.cpp +++ b/serializable.cpp @@ -33,18 +33,18 @@ bool copy_from_buf(const uint8_t** buf_ptr, const uint8_t* end, void* dest, size } bool copy_size_and_data_from_buf(const uint8_t** buf_ptr, const uint8_t* end, size_t* size, - uint8_t** dest) { + UniquePtr<uint8_t[]>* dest) { if (!copy_uint32_from_buf(buf_ptr, end, size) || *buf_ptr + *size > end) { return false; } if (*size == 0) { - *dest = NULL; + dest->reset(); return true; } - *dest = new uint8_t[*size]; - if (*dest == NULL) + dest->reset(new uint8_t[*size]); + if (dest->get() == NULL) return false; - return copy_from_buf(buf_ptr, end, *dest, *size); + return copy_from_buf(buf_ptr, end, dest->get(), *size); } } // namespace keymaster |