summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2015-07-29 13:53:36 -0700
committerThe Android Automerger <android-build@google.com>2015-08-13 19:41:57 -0700
commitbb9f4392c2f1b11be3acdc1737828274ff1ec55b (patch)
tree7b7a98657e51cf1dfe99324dd10da386d98d45c4
parentcd44a6b68316929039721ca5254bed48280dd40b (diff)
downloadsecurity-bb9f4392c2f1b11be3acdc1737828274ff1ec55b.tar.gz
Fix unchecked length in Blob creationandroid-5.1.1_r16android-5.1.1_r15android-5.1.1_r14
Applications can specify arbitrary blobs using insert(), check their length to prevent overflow issues. Bug:22802399 Change-Id: I4097bd891c733914df70da5e2c58783081d913bf
-rw-r--r--keystore/keystore.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index 63f7ee26..58d2fd6d 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -485,8 +485,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);