From 7f8fa65c5b44c4c41ae3efc0ba3f582afeec17c0 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Mon, 29 Mar 2021 13:26:21 -0500 Subject: [PATCH] asn1: Fix leak in der_copy_octet_string() This manifested as a leak via _save fields in the template backend. --- lib/asn1/der_copy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/asn1/der_copy.c b/lib/asn1/der_copy.c index b5e33b2f1..bd3d2404a 100644 --- a/lib/asn1/der_copy.c +++ b/lib/asn1/der_copy.c @@ -149,8 +149,12 @@ int ASN1CALL der_copy_octet_string (const heim_octet_string *from, heim_octet_string *to) { to->length = from->length; - to->data = malloc(to->length); - if(to->length != 0 && to->data == NULL) + if (from->data == NULL) { + to->data = NULL; + return 0; + } + to->data = malloc(to->length); + if (to->length != 0 && to->data == NULL) return ENOMEM; memcpy(to->data, from->data, to->length); return 0;