Ensure that the negative flag is correct set for ASN1 integer types.
authorPauli <ppzgs1@gmail.com>
Sun, 4 Apr 2021 03:58:22 +0000 (13:58 +1000)
committerPauli <pauli@openssl.org>
Wed, 7 Apr 2021 08:06:06 +0000 (18:06 +1000)
Reported by: Scott McPeak <scott.g.mcpeak@gmail.com>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14768)

crypto/asn1/a_int.c

index 92c58b341840565e8d4cef6aca64442b26acd3f7..6774ba627c3fdcc27040fa57915762797a5790ed 100644 (file)
@@ -308,8 +308,10 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
 
     c2i_ibuf(ret->data, &neg, *pp, len);
 
-    if (neg)
+    if (neg != 0)
         ret->type |= V_ASN1_NEG;
+    else
+        ret->type &= ~V_ASN1_NEG;
 
     *pp += len;
     if (a != NULL)
@@ -317,7 +319,7 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
     return ret;
  err:
     ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
-    if ((a == NULL) || (*a != ret))
+    if (a == NULL || *a != ret)
         ASN1_INTEGER_free(ret);
     return NULL;
 }