From 70a54261052a5a78a33b5b91d4f3ab699b55e2ef Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 1 Sep 2011 12:08:57 +0100 Subject: Fix the Java bridge to correctly handle null strings Passing null to methods expecting java/lang/String ... - Previously null was converted to the empty string but should be converted to Java null. - convertNPVariantToJavaValue() already converts a null NPVariant to a null WTF::String. - Fixed javaValueToJvalue() to convert a null WTF::String to a null jvalue. Returning null from a method with return type java/lang/String ... - Previously this would crash when trying to get the characters from the null jstring, but should return JavaScript undefined. - Fixed jvalueToJavaValue() to convert a null jvalue to a null WTF::String. - Fixed convertJavaValueToNPVariant() to convert a null WTF::String to a void NPVariant. Both of these are regressions from HC due to http://trac.webkit.org/changeset/82194. Added tests in https://android-git.corp.google.com/g/#/c/132580 Bug: 5222742 Change-Id: Id08bc7b40a51426fa7638ad0ed5260d09f3e28bb --- Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Source') diff --git a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp index 0d1a9f2..47b88d6 100644 --- a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp +++ b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp @@ -352,6 +352,13 @@ void convertJavaValueToNPVariant(JavaValue value, NPVariant* result) case JavaTypeString: { +#if PLATFORM(ANDROID) + // This entire file will likely be removed usptream soon. + if (value.m_stringValue.isNull()) { + VOID_TO_NPVARIANT(*result); + break; + } +#endif const char* utf8String = strdup(value.m_stringValue.utf8().data()); // The copied string is freed in NPN_ReleaseVariantValue (see npruntime.cpp) STRINGZ_TO_NPVARIANT(utf8String, *result); @@ -429,6 +436,10 @@ JavaValue jvalueToJavaValue(const jvalue& value, const JavaType& type) case JavaTypeString: { jstring javaString = static_cast(value.l); + if (!javaString) { + // result.m_stringValue is null by default + break; + } const UChar* characters = getUCharactersFromJStringInEnv(getJNIEnv(), javaString); // We take a copy to allow the Java String to be released. result.m_stringValue = String(characters, getJNIEnv()->GetStringLength(javaString)); @@ -487,6 +498,10 @@ jvalue javaValueToJvalue(const JavaValue& value) // be released when the call stack returns to Java. Note that this // may cause leaks if invoked from a native message loop, as is the // case in workers. + if (value.m_stringValue.isNull()) { + // result.l is null by default. + break; + } result.l = getJNIEnv()->NewString(value.m_stringValue.characters(), value.m_stringValue.length()); break; case JavaTypeBoolean: -- cgit v1.1