diff options
author | Brent Cook <bcook@cvs.openbsd.org> | 2016-11-06 14:00:50 +0000 |
---|---|---|
committer | Brent Cook <bcook@cvs.openbsd.org> | 2016-11-06 14:00:50 +0000 |
commit | 10f1a9b5268e8d45f643f0d7823b3cef18f88a4f (patch) | |
tree | d815166c45dd7f15c51409ce9ed6f58ef6dceb68 /lib/libcrypto/asn1 | |
parent | 93253c0ca1e57b3bb4d106c5f1f7dd944c0ce077 (diff) |
simplify error handling in c2i_ASN1_OBJECT
ok beck@, miod@
Diffstat (limited to 'lib/libcrypto/asn1')
-rw-r--r-- | lib/libcrypto/asn1/a_object.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/libcrypto/asn1/a_object.c b/lib/libcrypto/asn1/a_object.c index 5bf450d0e18..3cb0cf7c4b1 100644 --- a/lib/libcrypto/asn1/a_object.c +++ b/lib/libcrypto/asn1/a_object.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_object.c,v 1.26 2016/03/17 03:51:49 beck Exp $ */ +/* $OpenBSD: a_object.c,v 1.27 2016/11/06 14:00:49 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -284,7 +284,7 @@ err: ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) { - ASN1_OBJECT *ret = NULL; + ASN1_OBJECT *ret; const unsigned char *p; unsigned char *data; int i, length; @@ -307,7 +307,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING); - return NULL; + return (NULL); } } @@ -318,37 +318,39 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) if ((ret = ASN1_OBJECT_new()) == NULL) return (NULL); } else - ret = (*a); + ret = *a; p = *pp; + /* detach data from object */ data = (unsigned char *)ret->data; if (data != NULL) explicit_bzero(data, ret->length); free(data); + data = malloc(length); if (data == NULL) { - i = ERR_R_MALLOC_FAILURE; + ASN1err(ASN1_F_C2I_ASN1_OBJECT, ERR_R_MALLOC_FAILURE); goto err; } - ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; + memcpy(data, p, length); + /* reattach data to object, after which it remains const */ ret->data = data; ret->length = length; ret->sn = NULL; ret->ln = NULL; - /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ + ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; p += length; if (a != NULL) - (*a) = ret; + *a = ret; *pp = p; return (ret); err: - ASN1err(ASN1_F_C2I_ASN1_OBJECT, i); - if ((ret != NULL) && ((a == NULL) || (*a != ret))) + if (ret != *a) ASN1_OBJECT_free(ret); return (NULL); } |