diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-11-16 10:30:41 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-11-16 10:30:41 -0800 |
commit | d2bed869f45bd0f286f5916e58cdacde8bd66397 (patch) | |
tree | 699c2dd153e0f4db9b3b6f3ed9ec8a70ec5faf5e /luni/src | |
parent | 25c670d5f17355ac9c527a0f93a7783052618a7b (diff) | |
parent | 845ce3cbfd6972542b275c95eddfbb6e94469737 (diff) | |
download | libcore-d2bed869f45bd0f286f5916e58cdacde8bd66397.zip libcore-d2bed869f45bd0f286f5916e58cdacde8bd66397.tar.gz libcore-d2bed869f45bd0f286f5916e58cdacde8bd66397.tar.bz2 |
Merge change If8e2929a
* changes:
Don't allocate arbitrary-length buffers on the stack.
Diffstat (limited to 'luni/src')
-rw-r--r-- | luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp index 3f58736..b4b6d92 100644 --- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp +++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp @@ -25,6 +25,7 @@ #include "AndroidSystemNatives.h" #include "JNIHelp.h" +#include "LocalArray.h" #include "jni.h" #include <arpa/inet.h> @@ -485,13 +486,10 @@ static jbyteArray osNetworkSystem_ipStringToByteArray(JNIEnv* env, jclass, return NULL; } - // We need to reserve two extra bytes for the possible '[' and ']'. - char ipString[INET6_ADDRSTRLEN + 2]; + // Convert the String to UTF bytes. size_t byteCount = env->GetStringUTFLength(javaString); - if (byteCount + 1 > sizeof(ipString)) { - jniThrowException(env, "java/lang/IllegalArgumentException", "string too long"); - return NULL; - } + LocalArray<INET6_ADDRSTRLEN> bytes(byteCount + 1); + char* ipString = &bytes[0]; env->GetStringUTFRegion(javaString, 0, env->GetStringLength(javaString), ipString); // Accept IPv6 addresses (only) in square brackets for compatibility. |