summaryrefslogtreecommitdiff
path: root/crypto/bn/bn_print.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2015-06-11 17:56:16 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2015-06-11 17:56:16 +0000
commita9745f9a849725cad34f84351bed202839aade59 (patch)
tree686ec4279139441a2f9d947dceec492e54ff569c /crypto/bn/bn_print.c
parent3d2030852da420b820a661e7b19bb757487e2599 (diff)
Notes
Diffstat (limited to 'crypto/bn/bn_print.c')
-rw-r--r--crypto/bn/bn_print.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/bn/bn_print.c b/crypto/bn/bn_print.c
index 4dcaae32bf5c6..ab10b957ba27d 100644
--- a/crypto/bn/bn_print.c
+++ b/crypto/bn/bn_print.c
@@ -71,7 +71,12 @@ char *BN_bn2hex(const BIGNUM *a)
char *buf;
char *p;
- buf = (char *)OPENSSL_malloc(a->top * BN_BYTES * 2 + 2);
+ if (a->neg && BN_is_zero(a)) {
+ /* "-0" == 3 bytes including NULL terminator */
+ buf = OPENSSL_malloc(3);
+ } else {
+ buf = OPENSSL_malloc(a->top * BN_BYTES * 2 + 2);
+ }
if (buf == NULL) {
BNerr(BN_F_BN_BN2HEX, ERR_R_MALLOC_FAILURE);
goto err;