diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2014-04-20 23:30:13 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2014-04-20 23:30:13 +0000 |
commit | 25b6a731230b7d3326743c4a007580dc795d7446 (patch) | |
tree | 027d96ace90cbfc2fed0c6b3c4b1dc64504d7aeb | |
parent | 431f78b77959103b0a4416e70c3dac9566cd81c7 (diff) |
ASN1_STRING cleanup - realloc has handled NULL since I had a mullet
and parachute pants - and since it's obvious there is no guarantee
the caller doesn't pass in the data area in the argument, use memmove
instead of memcpy so overlapping areas are handled correctly.
Also, pointers can be usefully printed in hex with %p, in error messaeges
rather than the bizzaro stuff that was there using mystical buffer lengths
and abuse of strlcpy-converted-blindly-from-strcpy
-rw-r--r-- | lib/libcrypto/asn1/asn1_lib.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/libcrypto/asn1/asn1_lib.c b/lib/libcrypto/asn1/asn1_lib.c index 86cfdd3967d..f3b2f0480fb 100644 --- a/lib/libcrypto/asn1/asn1_lib.c +++ b/lib/libcrypto/asn1/asn1_lib.c @@ -373,7 +373,6 @@ ASN1_STRING_dup(const ASN1_STRING *str) int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) { - unsigned char *c; const char *data = _data; if (len < 0) { @@ -383,24 +382,19 @@ ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) len = strlen(data); } if ((str->length < len) || (str->data == NULL)) { - c = str->data; - if (c == NULL) - str->data = malloc(len + 1); - else - str->data = realloc(c, len + 1); - - if (str->data == NULL) { + unsigned char *tmp; + tmp = realloc(str->data, len + 1); + if (tmp == NULL) { ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); - str->data = c; return (0); } + str->data = tmp; } str->length = len; if (data != NULL) { - memcpy(str->data, data, len); - /* an allowance for strings :-) */ - str->data[len]='\0'; + memmove(str->data, data, len); } + str->data[str->length]='\0'; return (1); } @@ -465,11 +459,10 @@ ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) void asn1_add_error(const unsigned char *address, int offset) { - char buf1[DECIMAL_SIZE(address) + 1], buf2[DECIMAL_SIZE(offset) + 1]; - - snprintf(buf1, sizeof buf1, "%lu", (unsigned long)address); - snprintf(buf2, sizeof buf2, "%d", offset); - ERR_add_error_data(4, "address=", buf1, " offset=", buf2); + char tmp[128]; + (void) snprintf(tmp, sizeof(tmp), "address=%p offset=%d", + address, offset); + ERR_add_error_data(1, tmp); } int |