diff options
| author | tedu <> | 2014-04-23 20:21:23 +0000 |
|---|---|---|
| committer | tedu <> | 2014-04-23 20:21:23 +0000 |
| commit | 96c50cef9d7eaef43992f73f025bdca040890c42 (patch) | |
| tree | c60d3b7cdc7d864e38819ddef5540c4964e6010f | |
| parent | 0d15f5b8849bca4941e94d990f6b6c7331687f16 (diff) | |
| download | openbsd-96c50cef9d7eaef43992f73f025bdca040890c42.tar.gz openbsd-96c50cef9d7eaef43992f73f025bdca040890c42.tar.bz2 openbsd-96c50cef9d7eaef43992f73f025bdca040890c42.zip | |
if realloc failed, BIO_accept would leak memory and return NULL, causing
caller to crash. Fix leak and return an error instead. from Chad Loder
| -rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 13 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/bio/b_sock.c | 13 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index a6dd43f397..a7791b39e2 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
| @@ -449,7 +449,7 @@ BIO_accept(int sock, char **addr) | |||
| 449 | int ret = -1; | 449 | int ret = -1; |
| 450 | unsigned long l; | 450 | unsigned long l; |
| 451 | unsigned short port; | 451 | unsigned short port; |
| 452 | char *p; | 452 | char *p, *tmp; |
| 453 | 453 | ||
| 454 | struct { | 454 | struct { |
| 455 | /* | 455 | /* |
| @@ -534,11 +534,19 @@ BIO_accept(int sock, char **addr) | |||
| 534 | p = *addr; | 534 | p = *addr; |
| 535 | if (p) { | 535 | if (p) { |
| 536 | *p = '\0'; | 536 | *p = '\0'; |
| 537 | p = realloc(p, nl); | 537 | if (!(tmp = realloc(p, nl))) { |
| 538 | ret = -1; | ||
| 539 | free(p); | ||
| 540 | *addr = NULL; | ||
| 541 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
| 542 | goto end; | ||
| 543 | } | ||
| 544 | p = tmp; | ||
| 538 | } else { | 545 | } else { |
| 539 | p = malloc(nl); | 546 | p = malloc(nl); |
| 540 | } | 547 | } |
| 541 | if (p == NULL) { | 548 | if (p == NULL) { |
| 549 | ret = -1; | ||
| 542 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | 550 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
| 543 | goto end; | 551 | goto end; |
| 544 | } | 552 | } |
| @@ -553,6 +561,7 @@ BIO_accept(int sock, char **addr) | |||
| 553 | port = ntohs(sa.from.sa_in.sin_port); | 561 | port = ntohs(sa.from.sa_in.sin_port); |
| 554 | if (*addr == NULL) { | 562 | if (*addr == NULL) { |
| 555 | if ((p = malloc(24)) == NULL) { | 563 | if ((p = malloc(24)) == NULL) { |
| 564 | ret = -1; | ||
| 556 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | 565 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
| 557 | goto end; | 566 | goto end; |
| 558 | } | 567 | } |
diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index a6dd43f397..a7791b39e2 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c | |||
| @@ -449,7 +449,7 @@ BIO_accept(int sock, char **addr) | |||
| 449 | int ret = -1; | 449 | int ret = -1; |
| 450 | unsigned long l; | 450 | unsigned long l; |
| 451 | unsigned short port; | 451 | unsigned short port; |
| 452 | char *p; | 452 | char *p, *tmp; |
| 453 | 453 | ||
| 454 | struct { | 454 | struct { |
| 455 | /* | 455 | /* |
| @@ -534,11 +534,19 @@ BIO_accept(int sock, char **addr) | |||
| 534 | p = *addr; | 534 | p = *addr; |
| 535 | if (p) { | 535 | if (p) { |
| 536 | *p = '\0'; | 536 | *p = '\0'; |
| 537 | p = realloc(p, nl); | 537 | if (!(tmp = realloc(p, nl))) { |
| 538 | ret = -1; | ||
| 539 | free(p); | ||
| 540 | *addr = NULL; | ||
| 541 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | ||
| 542 | goto end; | ||
| 543 | } | ||
| 544 | p = tmp; | ||
| 538 | } else { | 545 | } else { |
| 539 | p = malloc(nl); | 546 | p = malloc(nl); |
| 540 | } | 547 | } |
| 541 | if (p == NULL) { | 548 | if (p == NULL) { |
| 549 | ret = -1; | ||
| 542 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | 550 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
| 543 | goto end; | 551 | goto end; |
| 544 | } | 552 | } |
| @@ -553,6 +561,7 @@ BIO_accept(int sock, char **addr) | |||
| 553 | port = ntohs(sa.from.sa_in.sin_port); | 561 | port = ntohs(sa.from.sa_in.sin_port); |
| 554 | if (*addr == NULL) { | 562 | if (*addr == NULL) { |
| 555 | if ((p = malloc(24)) == NULL) { | 563 | if ((p = malloc(24)) == NULL) { |
| 564 | ret = -1; | ||
| 556 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); | 565 | BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); |
| 557 | goto end; | 566 | goto end; |
| 558 | } | 567 | } |
