asn1: Avoid calling malloc with 0 argument

Caused problems reported by oss-fuzz

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18758
This commit is contained in:
Jakub Jelen 2019-11-07 13:45:24 +01:00 committed by Frank Morgner
parent cd51430ba7
commit cc917b541f
1 changed files with 6 additions and 4 deletions

View File

@ -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;