NativeCrypto: handle X.509 serial number 0

There is no need to try to convert numbers that are of zero length
because they'll be zero anyway. Returning NULL in this instance caused a
crash in X.509 code since it immediately tried to pass it to BigInteger
which through a NullPointerException.

(cherry picked from commit adadc611f606e693ed30b2e495326cb32968153d)

Bug: 9297758
Change-Id: I719ca7b8f086937ee25094bfe981987def855744
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 88833b5..6df0aa8 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
@@ -715,8 +715,7 @@
         return NULL;
     }
 
-    int len = BN_num_bytes(source) + 1;
-    jbyteArray javaBytes = env->NewByteArray(len);
+    jbyteArray javaBytes = env->NewByteArray(BN_num_bytes(source) + 1);
     ScopedByteArrayRW bytes(env, javaBytes);
     if (bytes.get() == NULL) {
         JNI_TRACE("bignumToArray(%p, %s) => NULL", source, sourceName);
@@ -732,7 +731,7 @@
         *tmp = 0x00;
     }
 
-    if (BN_bn2bin(source, tmp + 1) <= 0) {
+    if (BN_num_bytes(source) > 0 && BN_bn2bin(source, tmp + 1) <= 0) {
         throwExceptionIfNecessary(env, "bignumToArray");
         return NULL;
     }