From 445cb8df9a966543d45f72b37e7582190f81fbf2 Mon Sep 17 00:00:00 2001 From: Sergei Dryganets Date: Fri, 4 Aug 2017 03:32:52 +0000 Subject: [PATCH] LocalString doesn't have a check for nullptr which could cause a crash if nullptr passed. LocalString doesn't have a check for nullptr which causes a crash if null string passed --- .../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 6827ec282d19cb..7e60d2642300c4 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; + } } }