Fix ASN1_TYPE_get/set with type=V_ASN1_BOOLEAN
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 1 Jul 2019 07:06:02 +0000 (09:06 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 2 Jul 2019 14:24:19 +0000 (16:24 +0200)
BOOLEAN does not have valid data in the value.ptr member,
thus don't use it here.

Fixes #9276

[extended tests]

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9278)

(cherry picked from commit 6335f837cfa7eaf1202f2557bf2ba148987226e7)

crypto/asn1/a_type.c

index 0c7aebe3076b4ea4bba0fd2a633186a774ef6868..84e78df0f1647e610ed4ea18861f9897158037fa 100644 (file)
@@ -15,7 +15,9 @@
 
 int ASN1_TYPE_get(const ASN1_TYPE *a)
 {
-    if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
+    if (a->type == V_ASN1_BOOLEAN
+            || a->type == V_ASN1_NULL
+            || a->value.ptr != NULL)
         return a->type;
     else
         return 0;
@@ -23,7 +25,9 @@ int ASN1_TYPE_get(const ASN1_TYPE *a)
 
 void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
 {
-    if (a->value.ptr != NULL) {
+    if (a->type != V_ASN1_BOOLEAN
+            && a->type != V_ASN1_NULL
+            && a->value.ptr != NULL) {
         ASN1_TYPE **tmp_a = &a;
         asn1_primitive_free((ASN1_VALUE **)tmp_a, NULL, 0);
     }