diff options
author | beck <> | 2014-04-20 23:30:12 +0000 |
---|---|---|
committer | beck <> | 2014-04-20 23:30:12 +0000 |
commit | 72fecb100e62bfefd9ab2896db696ee6dee6d889 (patch) | |
tree | fe5d877da3343761189de81dac659353acf6cbfd /src | |
parent | 27f49c1a7508baad456a0489c04d91b7804693e8 (diff) | |
download | openbsd-72fecb100e62bfefd9ab2896db696ee6dee6d889.tar.gz openbsd-72fecb100e62bfefd9ab2896db696ee6dee6d889.tar.bz2 openbsd-72fecb100e62bfefd9ab2896db696ee6dee6d889.zip |
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 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 27 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/asn1/asn1_lib.c | 27 |
2 files changed, 20 insertions, 34 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 86cfdd3967..f3b2f0480f 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -373,7 +373,6 @@ ASN1_STRING_dup(const ASN1_STRING *str) | |||
373 | int | 373 | int |
374 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | 374 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) |
375 | { | 375 | { |
376 | unsigned char *c; | ||
377 | const char *data = _data; | 376 | const char *data = _data; |
378 | 377 | ||
379 | if (len < 0) { | 378 | if (len < 0) { |
@@ -383,24 +382,19 @@ ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
383 | len = strlen(data); | 382 | len = strlen(data); |
384 | } | 383 | } |
385 | if ((str->length < len) || (str->data == NULL)) { | 384 | if ((str->length < len) || (str->data == NULL)) { |
386 | c = str->data; | 385 | unsigned char *tmp; |
387 | if (c == NULL) | 386 | tmp = realloc(str->data, len + 1); |
388 | str->data = malloc(len + 1); | 387 | if (tmp == NULL) { |
389 | else | ||
390 | str->data = realloc(c, len + 1); | ||
391 | |||
392 | if (str->data == NULL) { | ||
393 | ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); | 388 | ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); |
394 | str->data = c; | ||
395 | return (0); | 389 | return (0); |
396 | } | 390 | } |
391 | str->data = tmp; | ||
397 | } | 392 | } |
398 | str->length = len; | 393 | str->length = len; |
399 | if (data != NULL) { | 394 | if (data != NULL) { |
400 | memcpy(str->data, data, len); | 395 | memmove(str->data, data, len); |
401 | /* an allowance for strings :-) */ | ||
402 | str->data[len]='\0'; | ||
403 | } | 396 | } |
397 | str->data[str->length]='\0'; | ||
404 | return (1); | 398 | return (1); |
405 | } | 399 | } |
406 | 400 | ||
@@ -465,11 +459,10 @@ ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | |||
465 | void | 459 | void |
466 | asn1_add_error(const unsigned char *address, int offset) | 460 | asn1_add_error(const unsigned char *address, int offset) |
467 | { | 461 | { |
468 | char buf1[DECIMAL_SIZE(address) + 1], buf2[DECIMAL_SIZE(offset) + 1]; | 462 | char tmp[128]; |
469 | 463 | (void) snprintf(tmp, sizeof(tmp), "address=%p offset=%d", | |
470 | snprintf(buf1, sizeof buf1, "%lu", (unsigned long)address); | 464 | address, offset); |
471 | snprintf(buf2, sizeof buf2, "%d", offset); | 465 | ERR_add_error_data(1, tmp); |
472 | ERR_add_error_data(4, "address=", buf1, " offset=", buf2); | ||
473 | } | 466 | } |
474 | 467 | ||
475 | int | 468 | int |
diff --git a/src/lib/libssl/src/crypto/asn1/asn1_lib.c b/src/lib/libssl/src/crypto/asn1/asn1_lib.c index 86cfdd3967..f3b2f0480f 100644 --- a/src/lib/libssl/src/crypto/asn1/asn1_lib.c +++ b/src/lib/libssl/src/crypto/asn1/asn1_lib.c | |||
@@ -373,7 +373,6 @@ ASN1_STRING_dup(const ASN1_STRING *str) | |||
373 | int | 373 | int |
374 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | 374 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) |
375 | { | 375 | { |
376 | unsigned char *c; | ||
377 | const char *data = _data; | 376 | const char *data = _data; |
378 | 377 | ||
379 | if (len < 0) { | 378 | if (len < 0) { |
@@ -383,24 +382,19 @@ ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | |||
383 | len = strlen(data); | 382 | len = strlen(data); |
384 | } | 383 | } |
385 | if ((str->length < len) || (str->data == NULL)) { | 384 | if ((str->length < len) || (str->data == NULL)) { |
386 | c = str->data; | 385 | unsigned char *tmp; |
387 | if (c == NULL) | 386 | tmp = realloc(str->data, len + 1); |
388 | str->data = malloc(len + 1); | 387 | if (tmp == NULL) { |
389 | else | ||
390 | str->data = realloc(c, len + 1); | ||
391 | |||
392 | if (str->data == NULL) { | ||
393 | ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); | 388 | ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); |
394 | str->data = c; | ||
395 | return (0); | 389 | return (0); |
396 | } | 390 | } |
391 | str->data = tmp; | ||
397 | } | 392 | } |
398 | str->length = len; | 393 | str->length = len; |
399 | if (data != NULL) { | 394 | if (data != NULL) { |
400 | memcpy(str->data, data, len); | 395 | memmove(str->data, data, len); |
401 | /* an allowance for strings :-) */ | ||
402 | str->data[len]='\0'; | ||
403 | } | 396 | } |
397 | str->data[str->length]='\0'; | ||
404 | return (1); | 398 | return (1); |
405 | } | 399 | } |
406 | 400 | ||
@@ -465,11 +459,10 @@ ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | |||
465 | void | 459 | void |
466 | asn1_add_error(const unsigned char *address, int offset) | 460 | asn1_add_error(const unsigned char *address, int offset) |
467 | { | 461 | { |
468 | char buf1[DECIMAL_SIZE(address) + 1], buf2[DECIMAL_SIZE(offset) + 1]; | 462 | char tmp[128]; |
469 | 463 | (void) snprintf(tmp, sizeof(tmp), "address=%p offset=%d", | |
470 | snprintf(buf1, sizeof buf1, "%lu", (unsigned long)address); | 464 | address, offset); |
471 | snprintf(buf2, sizeof buf2, "%d", offset); | 465 | ERR_add_error_data(1, tmp); |
472 | ERR_add_error_data(4, "address=", buf1, " offset=", buf2); | ||
473 | } | 466 | } |
474 | 467 | ||
475 | int | 468 | int |