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 | 3f2a400f6e211137fd0d7c3600170a7c8f93602f (patch) | |
tree | f5efed2e2f26ac21e695ce5ee923118466fba828 /lib | |
parent | 9e68d28fa6cb5bc73be65c137ab464c74a715df3 (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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libssl/src/crypto/asn1/asn1_lib.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/lib/libssl/src/crypto/asn1/asn1_lib.c b/lib/libssl/src/crypto/asn1/asn1_lib.c index 86cfdd3967d..f3b2f0480fb 100644 --- a/lib/libssl/src/crypto/asn1/asn1_lib.c +++ b/lib/libssl/src/crypto/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 |