From 7e515479b0e1156d9bae3fd2b5aab17f1aaa65be Mon Sep 17 00:00:00 2001 From: Sergei Dryganets Date: Thu, 10 Aug 2017 03:09:46 -0700 Subject: [PATCH] LocalString doesn't have a check for nullptr Summary: LocalString doesn't have a check for null ptr which causes a crash if the null string passed. Closes https://github.com/facebook/react-native/pull/15372 Differential Revision: D5601469 Pulled By: javache fbshipit-source-id: a1b20efbae90009f0d465c077e6401a701d7515f --- .../jni/first-party/fb/jni/LocalString.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ReactAndroid/src/main/jni/first-party/fb/jni/LocalString.cpp b/ReactAndroid/src/main/jni/first-party/fb/jni/LocalString.cpp index 6827ec282d1..7e60d264230 100644 --- a/ReactAndroid/src/main/jni/first-party/fb/jni/LocalString.cpp +++ b/ReactAndroid/src/main/jni/first-party/fb/jni/LocalString.cpp @@ -82,16 +82,18 @@ size_t modifiedLength(const uint8_t* str, size_t* length) { // NUL-terminated: Scan for length and supplementary characters size_t i = 0; size_t j = 0; - while (str[i] != 0) { - if (str[i + 1] == 0 || - str[i + 2] == 0 || - str[i + 3] == 0 || - !isFourByteUTF8Encoding(&(str[i]))) { - i += 1; - j += 1; - } else { - i += 4; - j += 6; + if (str != nullptr) { + while (str[i] != 0) { + if (str[i + 1] == 0 || + str[i + 2] == 0 || + str[i + 3] == 0 || + !isFourByteUTF8Encoding(&(str[i]))) { + i += 1; + j += 1; + } else { + i += 4; + j += 6; + } } }