asn1: Fix leak in der_copy_octet_string()

This manifested as a leak via _save fields in the template backend.
This commit is contained in:
Nicolas Williams
2021-03-29 13:26:21 -05:00
parent a7e11df142
commit 7f8fa65c5b

View File

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