summaryrefslogtreecommitdiff
path: root/lib/libcrypto/asn1/tasn_new.c
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2019-04-01 15:48:05 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2019-04-01 15:48:05 +0000
commit9fd1c4993fe78af63999bc7adab9194f65ca030e (patch)
tree68e87b4eb212987f1331867302e9627c801d7352 /lib/libcrypto/asn1/tasn_new.c
parentdb0fee1f0cf56f66603e3251b424ec2b6d47baca (diff)
Require all ASN1_PRIMITIVE_FUNCS functions to be provided.
If an ASN.1 item provides its own ASN1_PRIMITIVE_FUNCS functions, require all functions to be provided (currently excluding prim_clear). This avoids situations such as having a custom allocator that returns a specific struct but then is then printed using the default primative print functions, which interpret the memory as a different struct. Found by oss-fuzz, fixes issue #13799. ok beck@, tb@
Diffstat (limited to 'lib/libcrypto/asn1/tasn_new.c')
-rw-r--r--lib/libcrypto/asn1/tasn_new.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/libcrypto/asn1/tasn_new.c b/lib/libcrypto/asn1/tasn_new.c
index e9bbc05e088..7c9bb989746 100644
--- a/lib/libcrypto/asn1/tasn_new.c
+++ b/lib/libcrypto/asn1/tasn_new.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tasn_new.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
+/* $OpenBSD: tasn_new.c,v 1.18 2019/04/01 15:48:04 jsing Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@@ -306,10 +306,12 @@ ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
ASN1_STRING *str;
int utype;
- if (it && it->funcs) {
+ if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
- if (pf->prim_new)
- return pf->prim_new(pval, it);
+
+ if (pf->prim_new == NULL)
+ return 0;
+ return pf->prim_new(pval, it);
}
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
@@ -355,14 +357,17 @@ static void
asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
int utype;
- if (it && it->funcs) {
+
+ if (it != NULL && it->funcs != NULL) {
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
+
if (pf->prim_clear)
pf->prim_clear(pval, it);
else
*pval = NULL;
return;
}
+
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
utype = V_ASN1_UNDEF;
else