Skip to content
Permalink
Browse files

IDN: Fix handling of long domain names.

We were incorrectly using sizeof() to calculate the size of the
output array. Note that this change also changes the output size
to 512 to minimize behavioural differences (especially wrt. ICU
checks on sizes).

bug: 30765246
Change-Id: I5d28ddc45d2d6d2bed3e479ca195ed2779b906ed
(cherry picked from commit fffeb3b)
  • Loading branch information...
narayank authored and andi34 committed Aug 19, 2016
1 parent 30d2012 commit 42e44efe71e82085b9b3fef002bb0a1e25cfcb96
Showing with 15 additions and 3 deletions.
  1. +4 −3 luni/src/main/native/libcore_icu_NativeIDN.cpp
  2. +11 −0 luni/src/test/java/libcore/java/net/IDNTest.java
@@ -37,11 +37,12 @@ static jstring NativeIDN_convertImpl(JNIEnv* env, jclass, jstring javaSrc, jint
if (src.get() == NULL) {
return NULL;
}
UChar dst[256];
static const size_t kDstSize = 512;
UChar dst[kDstSize];
UErrorCode status = U_ZERO_ERROR;
size_t resultLength = toAscii
? uidna_IDNToASCII(src.get(), src.size(), &dst[0], sizeof(dst), flags, NULL, &status)
: uidna_IDNToUnicode(src.get(), src.size(), &dst[0], sizeof(dst), flags, NULL, &status);
? uidna_IDNToASCII(src.get(), src.size(), &dst[0], kDstSize, flags, NULL, &status)
: uidna_IDNToUnicode(src.get(), src.size(), &dst[0], kDstSize, flags, NULL, &status);
if (U_FAILURE(status)) {
jniThrowException(env, "java/lang/IllegalArgumentException", u_errorName(status));
return NULL;
@@ -37,4 +37,15 @@ public void test_toUnicode_failures() {
String longInput = makePunyString(512);
assertEquals(longInput, IDN.toUnicode(longInput));
}

// http://b/30765246
public void testLongDomainName() {
String label63 = "123456789-123456789-123456789-123456789-123456789-123456789-123";
String host255 = label63 + "." + label63 + "." + label63 + "." + label63;
try {
IDN.toASCII(host255.substring(3) + ".com");
fail();
} catch (IllegalArgumentException expected) {
}
}
}

0 comments on commit 42e44ef

Please sign in to comment.
You can’t perform that action at this time.