Skip to content

Commit 72eade5

Browse files
chadbrubakerandi34
authored andcommitted
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
1 parent ee8068b commit 72eade5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

keystore/keystore.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,16 @@ static const uint8_t CURRENT_BLOB_VERSION = 2;
410410

411411
class Blob {
412412
public:
413-
Blob(const uint8_t* value, int32_t valueLength, const uint8_t* info, uint8_t infoLength,
413+
Blob(const uint8_t* value, size_t valueLength, const uint8_t* info, uint8_t infoLength,
414414
BlobType type) {
415+
if (valueLength > sizeof(mBlob.value)) {
416+
valueLength = sizeof(mBlob.value);
417+
ALOGW("Provided blob length too large");
418+
}
419+
if (infoLength + valueLength > sizeof(mBlob.value)) {
420+
infoLength = sizeof(mBlob.value) - valueLength;
421+
ALOGW("Provided info length too large");
422+
}
415423
mBlob.length = valueLength;
416424
memcpy(mBlob.value, value, valueLength);
417425

0 commit comments

Comments
 (0)