From cc917b541f353c71353a826568d4becdf8d66293 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 7 Nov 2019 13:45:24 +0100 Subject: [PATCH] asn1: Avoid calling malloc with 0 argument Caused problems reported by oss-fuzz https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18758 --- src/libopensc/asn1.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c index 4e95fe78..299de5b2 100644 --- a/src/libopensc/asn1.c +++ b/src/libopensc/asn1.c @@ -1500,10 +1500,12 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry, /* Allocate buffer if needed */ if (entry->flags & SC_ASN1_ALLOC) { u8 **buf = (u8 **) parm; - *buf = malloc(objlen); - if (*buf == NULL) { - r = SC_ERROR_OUT_OF_MEMORY; - break; + if (objlen > 0) { + *buf = malloc(objlen); + if (*buf == NULL) { + r = SC_ERROR_OUT_OF_MEMORY; + break; + } } c = *len = objlen; parm = *buf;