From d6c4771174501c9b2e814ba41f3a0358ded80b43 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 10 Mar 2023 09:56:09 +0000 Subject: [PATCH] Return the correct type for ASN.1 BOOLEANs ASN.1 BOOLEANs and ASN.1 NULL are handled specially in the ASN.1 sausage factory and they are special in that they don't have a->value.ptr set. Both need to be special cased here since they fail the a->type.ptr != NULL check. Apart from fixing an obvious bug in ASN1_TYPE_get(), this fixes another crash in openssl(1) asn1parse. There is more to do in the vicinity, but that is more complex and will have to wait for OpenBSD 7.3-current. with/ok jsing --- lib/libcrypto/asn1/a_type.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/libcrypto/asn1/a_type.c b/lib/libcrypto/asn1/a_type.c index 61609c38f7b..684321756f6 100644 --- a/lib/libcrypto/asn1/a_type.c +++ b/lib/libcrypto/asn1/a_type.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_type.c,v 1.23 2021/12/25 12:19:16 jsing Exp $ */ +/* $OpenBSD: a_type.c,v 1.24 2023/03/10 09:56:09 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -104,10 +104,14 @@ ASN1_TYPE_free(ASN1_TYPE *a) int ASN1_TYPE_get(const ASN1_TYPE *a) { - if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) - return (a->type); - else - return (0); + /* Special non-pointer types. */ + if (a->type == V_ASN1_BOOLEAN || a->type == V_ASN1_NULL ) + return a->type; + + if (a->value.ptr != NULL) + return a->type; + + return 0; } void -- 2.20.1