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;