diff options
author | tedu <> | 2015-10-14 21:12:10 +0000 |
---|---|---|
committer | tedu <> | 2015-10-14 21:12:10 +0000 |
commit | e8ea76a11af489c64a364323e8d0402a41f9cb90 (patch) | |
tree | 59b9f9081751de94c448846f2284d7525502494e /src | |
parent | b94124f8caf871e87767ee543513ae2e02968268 (diff) | |
download | openbsd-e8ea76a11af489c64a364323e8d0402a41f9cb90.tar.gz openbsd-e8ea76a11af489c64a364323e8d0402a41f9cb90.tar.bz2 openbsd-e8ea76a11af489c64a364323e8d0402a41f9cb90.zip |
fix a memory leak reported by Qualys Security.
move the bndec variable in tighter since it's not used elsewhere in the
loop, then always free it after use.
ok bcook miod
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/objects/obj_dat.c | 7 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/objects/obj_dat.c | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 82ebb9b1d2..dab860d85c 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_dat.c,v 1.32 2015/10/14 21:02:08 beck Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.33 2015/10/14 21:12:10 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -491,7 +491,6 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
491 | { | 491 | { |
492 | int i, ret = 0, len, nid, first = 1, use_bn; | 492 | int i, ret = 0, len, nid, first = 1, use_bn; |
493 | BIGNUM *bl = NULL; | 493 | BIGNUM *bl = NULL; |
494 | char *bndec = NULL; | ||
495 | unsigned long l; | 494 | unsigned long l; |
496 | const unsigned char *p; | 495 | const unsigned char *p; |
497 | 496 | ||
@@ -567,10 +566,13 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
567 | } | 566 | } |
568 | 567 | ||
569 | if (use_bn) { | 568 | if (use_bn) { |
569 | char *bndec; | ||
570 | |||
570 | bndec = BN_bn2dec(bl); | 571 | bndec = BN_bn2dec(bl); |
571 | if (!bndec) | 572 | if (!bndec) |
572 | goto err; | 573 | goto err; |
573 | i = snprintf(buf, buf_len, ".%s", bndec); | 574 | i = snprintf(buf, buf_len, ".%s", bndec); |
575 | free(bndec); | ||
574 | if (i == -1) | 576 | if (i == -1) |
575 | goto err; | 577 | goto err; |
576 | if (i >= buf_len) { | 578 | if (i >= buf_len) { |
@@ -598,7 +600,6 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
598 | } | 600 | } |
599 | 601 | ||
600 | out: | 602 | out: |
601 | free(bndec); | ||
602 | BN_free(bl); | 603 | BN_free(bl); |
603 | return ret; | 604 | return ret; |
604 | 605 | ||
diff --git a/src/lib/libssl/src/crypto/objects/obj_dat.c b/src/lib/libssl/src/crypto/objects/obj_dat.c index 82ebb9b1d2..dab860d85c 100644 --- a/src/lib/libssl/src/crypto/objects/obj_dat.c +++ b/src/lib/libssl/src/crypto/objects/obj_dat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: obj_dat.c,v 1.32 2015/10/14 21:02:08 beck Exp $ */ | 1 | /* $OpenBSD: obj_dat.c,v 1.33 2015/10/14 21:12:10 tedu Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -491,7 +491,6 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
491 | { | 491 | { |
492 | int i, ret = 0, len, nid, first = 1, use_bn; | 492 | int i, ret = 0, len, nid, first = 1, use_bn; |
493 | BIGNUM *bl = NULL; | 493 | BIGNUM *bl = NULL; |
494 | char *bndec = NULL; | ||
495 | unsigned long l; | 494 | unsigned long l; |
496 | const unsigned char *p; | 495 | const unsigned char *p; |
497 | 496 | ||
@@ -567,10 +566,13 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
567 | } | 566 | } |
568 | 567 | ||
569 | if (use_bn) { | 568 | if (use_bn) { |
569 | char *bndec; | ||
570 | |||
570 | bndec = BN_bn2dec(bl); | 571 | bndec = BN_bn2dec(bl); |
571 | if (!bndec) | 572 | if (!bndec) |
572 | goto err; | 573 | goto err; |
573 | i = snprintf(buf, buf_len, ".%s", bndec); | 574 | i = snprintf(buf, buf_len, ".%s", bndec); |
575 | free(bndec); | ||
574 | if (i == -1) | 576 | if (i == -1) |
575 | goto err; | 577 | goto err; |
576 | if (i >= buf_len) { | 578 | if (i >= buf_len) { |
@@ -598,7 +600,6 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
598 | } | 600 | } |
599 | 601 | ||
600 | out: | 602 | out: |
601 | free(bndec); | ||
602 | BN_free(bl); | 603 | BN_free(bl); |
603 | return ret; | 604 | return ret; |
604 | 605 | ||