summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2011-06-07 13:23:11 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-06-07 13:23:11 -0700
commit4c5f2a9dd26674be797e1cb7c995247601096a04 (patch)
tree4775af7361935b791b38e3d5def44842ac563e7a /core/jni
parent1f8665895f71904b9d757854277cb637841356c3 (diff)
parented1c8d7dc09996351db711be7d2acf0ff4715c2d (diff)
downloadframeworks_base-4c5f2a9dd26674be797e1cb7c995247601096a04.zip
frameworks_base-4c5f2a9dd26674be797e1cb7c995247601096a04.tar.gz
frameworks_base-4c5f2a9dd26674be797e1cb7c995247601096a04.tar.bz2
am ed1c8d7d: am 0aa1017f: Prevent allocation overflows by corrupt NDEF records.
* commit 'ed1c8d7dc09996351db711be7d2acf0ff4715c2d': Prevent allocation overflows by corrupt NDEF records.
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_nfc_NdefMessage.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/jni/android_nfc_NdefMessage.cpp b/core/jni/android_nfc_NdefMessage.cpp
index 9beef2a..aff8aa6 100644
--- a/core/jni/android_nfc_NdefMessage.cpp
+++ b/core/jni/android_nfc_NdefMessage.cpp
@@ -102,6 +102,19 @@ static jint android_nfc_NdefMessage_parseNdefMessage(JNIEnv *e, jobject o,
}
TRACE("phFriNfc_NdefRecord_Parse() returned 0x%04x", status);
+ // We don't exactly know what *is* a valid length, but a simple
+ // sanity check is to make sure that the length of the header
+ // plus all fields does not exceed raw_msg_size. The min length
+ // of the header is 3 bytes: TNF, Type Length, Payload Length
+ // (ID length field is optional!)
+ uint64_t indicatedMsgLength = 3 + record.TypeLength + record.IdLength +
+ (uint64_t)record.PayloadLength;
+ if (indicatedMsgLength >
+ (uint64_t)raw_msg_size) {
+ LOGE("phFri_NdefRecord_Parse: invalid length field");
+ goto end;
+ }
+
type = e->NewByteArray(record.TypeLength);
if (type == NULL) {
LOGD("NFC_Set Record Type Error\n");