diff options
author | Elliott Hughes <enh@google.com> | 2010-05-26 17:45:07 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-05-26 23:52:54 -0700 |
commit | 05960876dff6a5b686821eed8f7ae7cef5af4f50 (patch) | |
tree | 56403ecb87974f4f17b02d996ed828cb74054118 /openssl/src/main | |
parent | 2be0ae9c8abc05d1c94c8bb170503ee2feae1866 (diff) | |
download | libcore-05960876dff6a5b686821eed8f7ae7cef5af4f50.zip libcore-05960876dff6a5b686821eed8f7ae7cef5af4f50.tar.gz libcore-05960876dff6a5b686821eed8f7ae7cef5af4f50.tar.bz2 |
Enhance ScopedUtfChars to include the null check most callers were missing.
Also switch most non-users over to ScopedUtfChars.
Also ensure all users check that ScopedUtfChars was successful in getting the
chars.
Also rewrite ObjectInputStream and ObjectOutputStream without duplication.
Change-Id: I929d00fe3ff50b303cba4a2cf2269355e9fef5f9
Diffstat (limited to 'openssl/src/main')
-rw-r--r-- | openssl/src/main/native/BNInterface.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/openssl/src/main/native/BNInterface.cpp b/openssl/src/main/native/BNInterface.cpp index a40192c..ea93895 100644 --- a/openssl/src/main/native/BNInterface.cpp +++ b/openssl/src/main/native/BNInterface.cpp @@ -20,6 +20,7 @@ #include "JNIHelp.h" #include "ScopedPrimitiveArray.h" +#include "ScopedUtfChars.h" #include "jni.h" #include <assert.h> #include <openssl/bn.h> @@ -150,27 +151,23 @@ static jboolean NativeBN_putLongInt(JNIEnv* env, jclass cls, BIGNUM* a, long lon */ static int NativeBN_BN_dec2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) { if (!oneValidHandle(env, a)) return -1; - char* tmpStr = (char*)env->GetStringUTFChars(str, NULL); - if (tmpStr != NULL) { - int len = BN_dec2bn(&a, tmpStr); - env->ReleaseStringUTFChars(str, tmpStr); - return len; // len == 0: Error + ScopedUtfChars chars(env, str); + if (chars.c_str() == NULL) { + return -1; } - else return -1; // Error outside BN. + return BN_dec2bn(&a, chars.c_str()); } /** * public static native int BN_hex2bn(int, java.lang.String) */ static int NativeBN_BN_hex2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) { - if (!oneValidHandle(env, a)) return -1; - char* tmpStr = (char*)env->GetStringUTFChars(str, NULL); - if (tmpStr != NULL) { - int len = BN_hex2bn(&a, tmpStr); - env->ReleaseStringUTFChars(str, tmpStr); - return len; // len == 0: Error + if (!oneValidHandle(env, a)) return -1; + ScopedUtfChars chars(env, str); + if (chars.c_str() == NULL) { + return -1; } - else return -1; // Error outside BN. + return BN_hex2bn(&a, chars.c_str()); } /** |