Fix encoding bug in i2c_ASN1_INTEGER (Imported from upstream's 3661bb4e7934668bd99ca777ea8b30eedfafa871.) Fix bug where i2c_ASN1_INTEGER mishandles zero if it is marked as negative. Thanks to Huzaifa Sidhpurwala <huzaifas@redhat.com> and Hanno Böck <hanno@hboeck.de> for reporting this issue. BUG=590615 (Cherry-picked from c4eec0c16b02c97a62a95b6a08656c3a9ddb6baa.) Change-Id: I61c5556e8a065817e3d36569433bff83a104d4c8 Reviewed-on: https://boringssl-review.googlesource.com/7297 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c index 9a56534..fcd33a7 100644 --- a/crypto/asn1/a_int.c +++ b/crypto/asn1/a_int.c
@@ -125,6 +125,8 @@ { ret=a->length; i=a->data[0]; + if (ret == 1 && i == 0) + neg = 0; if (!neg && (i > 127)) { pad=1; pb=0; @@ -158,7 +160,7 @@ p += a->length - 1; i = a->length; /* Copy zeros to destination as long as source is zero */ - while(!*n) { + while(!*n && i > 1) { *(p--) = 0; n--; i--;