crypto/asn1: Assert on negative length value

Negative span size does not make sense.

Update-Note: We do not expect you to set the length of an ASN1_STRING to
be negative. To be safe, we will assert nonnegativity and abort if
otherwise in ASN1_STRING_set0.

Signed-off-by: Xiangfei Ding <xfding@google.com>
Change-Id: Ic87d43f598997a775d0b469413cbb02d6a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/104108
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/crypto/asn1/asn1_lib.cc b/crypto/asn1/asn1_lib.cc
index e41e43e..70d2192 100644
--- a/crypto/asn1/asn1_lib.cc
+++ b/crypto/asn1/asn1_lib.cc
@@ -280,6 +280,7 @@
 }
 
 void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) {
+  BSSL_CHECK(len >= 0);
   OPENSSL_free(str->data);
   str->data = reinterpret_cast<uint8_t *>(data);
   str->length = len;