Merge "NativeCrypto: reject non-IA5String altnames"
diff --git a/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp b/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
index 56b771a..aafba3a 100644
--- a/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
+++ b/luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
@@ -3824,8 +3824,16 @@
switch (gen->type) {
case GEN_EMAIL:
case GEN_DNS:
- case GEN_URI:
- return env->NewStringUTF(reinterpret_cast<char*>(ASN1_STRING_data(gen->d.ia5)));
+ case GEN_URI: {
+ // This must be an IA5String and must not contain NULLs.
+ char* data = reinterpret_cast<char*>(ASN1_STRING_data(gen->d.ia5));
+ if ((ASN1_STRING_type(gen->d.ia5) == V_ASN1_IA5STRING)
+ && (static_cast<size_t>(ASN1_STRING_length(gen->d.ia5)) == strlen(data))) {
+ return env->NewStringUTF(data);
+ } else {
+ return NULL;
+ }
+ }
case GEN_DIRNAME:
/* Write in RFC 2253 format */
return X509_NAME_to_jstring(env, gen->d.directoryName, XN_FLAG_RFC2253);