diff options
author | Chad Brubaker <cbrubaker@google.com> | 2015-07-29 13:53:36 -0700 |
---|---|---|
committer | Chad Brubaker <cbrubaker@google.com> | 2015-07-29 14:32:49 -0700 |
commit | b124c9e86a5f8466f527501c6677b4b1b165c0b1 (patch) | |
tree | f23e09f347d3c921468f0bbb3d15c9363c8a8d01 | |
parent | ee8068b9e7bfb2770635062fc9c2035be2142bd8 (diff) | |
download | android_system_security-b124c9e86a5f8466f527501c6677b4b1b165c0b1.tar.gz android_system_security-b124c9e86a5f8466f527501c6677b4b1b165c0b1.tar.bz2 android_system_security-b124c9e86a5f8466f527501c6677b4b1b165c0b1.zip |
Fix unchecked length in Blob creation
Applications can specify arbitrary blobs using insert(), check their
length to prevent overflow issues.
Bug:22802399
Change-Id: I4097bd891c733914df70da5e2c58783081d913bf
-rw-r--r-- | keystore/keystore.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp index 7366c34..031f4c8 100644 --- a/keystore/keystore.cpp +++ b/keystore/keystore.cpp @@ -410,8 +410,16 @@ static const uint8_t CURRENT_BLOB_VERSION = 2; class Blob { public: - Blob(const uint8_t* value, int32_t valueLength, const uint8_t* info, uint8_t infoLength, + Blob(const uint8_t* value, size_t valueLength, const uint8_t* info, uint8_t infoLength, BlobType type) { + if (valueLength > sizeof(mBlob.value)) { + valueLength = sizeof(mBlob.value); + ALOGW("Provided blob length too large"); + } + if (infoLength + valueLength > sizeof(mBlob.value)) { + infoLength = sizeof(mBlob.value) - valueLength; + ALOGW("Provided info length too large"); + } mBlob.length = valueLength; memcpy(mBlob.value, value, valueLength); |