diff options
| author | sthen <> | 2015-09-18 09:00:04 +0000 |
|---|---|---|
| committer | sthen <> | 2015-09-18 09:00:04 +0000 |
| commit | 8a2b62a8c45beb43a75c8994a301e68c2f3a2e18 (patch) | |
| tree | 5b4404dccb34895d939663a6adac79ddd29ba8fb /src/lib/libc | |
| parent | e3b81c11125abd29954e4494fc0ea9ea3ed35c38 (diff) | |
| download | openbsd-8a2b62a8c45beb43a75c8994a301e68c2f3a2e18.tar.gz openbsd-8a2b62a8c45beb43a75c8994a301e68c2f3a2e18.tar.bz2 openbsd-8a2b62a8c45beb43a75c8994a301e68c2f3a2e18.zip | |
Revert bn_print.c:r1.25 ("handle negative-zero in BN_bn2dec() too") for
now, it has a NULL deref. Segfault reported by Mikolaj Kucharski, ok bcook
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_print.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c index a68412c8a8..021ed23d96 100644 --- a/src/lib/libcrypto/bn/bn_print.c +++ b/src/lib/libcrypto/bn/bn_print.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bn_print.c,v 1.25 2015/09/13 16:02:11 deraadt Exp $ */ | 1 | /* $OpenBSD: bn_print.c,v 1.26 2015/09/18 09:00:04 sthen 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 | * |
| @@ -114,20 +114,6 @@ BN_bn2dec(const BIGNUM *a) | |||
| 114 | BIGNUM *t = NULL; | 114 | BIGNUM *t = NULL; |
| 115 | BN_ULONG *bn_data = NULL, *lp; | 115 | BN_ULONG *bn_data = NULL, *lp; |
| 116 | 116 | ||
| 117 | if (BN_is_zero(t)) { | ||
| 118 | buf = malloc(BN_is_negative(t) + 2); | ||
| 119 | if (buf == NULL) { | ||
| 120 | BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | p = buf; | ||
| 124 | if (BN_is_negative(t)) | ||
| 125 | *(p++) = '-'; | ||
| 126 | *(p++) = '0'; | ||
| 127 | *(p++) = '\0'; | ||
| 128 | return (buf); | ||
| 129 | } | ||
| 130 | |||
| 131 | /* get an upper bound for the length of the decimal integer | 117 | /* get an upper bound for the length of the decimal integer |
| 132 | * num <= (BN_num_bits(a) + 1) * log(2) | 118 | * num <= (BN_num_bits(a) + 1) * log(2) |
| 133 | * <= 3 * BN_num_bits(a) * 0.1001 + log(2) + 1 (rounding error) | 119 | * <= 3 * BN_num_bits(a) * 0.1001 + log(2) + 1 (rounding error) |
| @@ -147,26 +133,31 @@ BN_bn2dec(const BIGNUM *a) | |||
| 147 | #define BUF_REMAIN (num+3 - (size_t)(p - buf)) | 133 | #define BUF_REMAIN (num+3 - (size_t)(p - buf)) |
| 148 | p = buf; | 134 | p = buf; |
| 149 | lp = bn_data; | 135 | lp = bn_data; |
| 150 | if (BN_is_negative(t)) | 136 | if (BN_is_zero(t)) { |
| 151 | *p++ = '-'; | 137 | *(p++) = '0'; |
| 138 | *(p++) = '\0'; | ||
| 139 | } else { | ||
| 140 | if (BN_is_negative(t)) | ||
| 141 | *p++ = '-'; | ||
| 152 | 142 | ||
| 153 | i = 0; | 143 | i = 0; |
| 154 | while (!BN_is_zero(t)) { | 144 | while (!BN_is_zero(t)) { |
| 155 | *lp = BN_div_word(t, BN_DEC_CONV); | 145 | *lp = BN_div_word(t, BN_DEC_CONV); |
| 156 | lp++; | 146 | lp++; |
| 157 | } | 147 | } |
| 158 | lp--; | ||
| 159 | /* We now have a series of blocks, BN_DEC_NUM chars | ||
| 160 | * in length, where the last one needs truncation. | ||
| 161 | * The blocks need to be reversed in order. */ | ||
| 162 | snprintf(p, BUF_REMAIN, BN_DEC_FMT1, *lp); | ||
| 163 | while (*p) | ||
| 164 | p++; | ||
| 165 | while (lp != bn_data) { | ||
| 166 | lp--; | 148 | lp--; |
| 167 | snprintf(p, BUF_REMAIN, BN_DEC_FMT2, *lp); | 149 | /* We now have a series of blocks, BN_DEC_NUM chars |
| 150 | * in length, where the last one needs truncation. | ||
| 151 | * The blocks need to be reversed in order. */ | ||
| 152 | snprintf(p, BUF_REMAIN, BN_DEC_FMT1, *lp); | ||
| 168 | while (*p) | 153 | while (*p) |
| 169 | p++; | 154 | p++; |
| 155 | while (lp != bn_data) { | ||
| 156 | lp--; | ||
| 157 | snprintf(p, BUF_REMAIN, BN_DEC_FMT2, *lp); | ||
| 158 | while (*p) | ||
| 159 | p++; | ||
| 160 | } | ||
| 170 | } | 161 | } |
| 171 | ok = 1; | 162 | ok = 1; |
| 172 | 163 | ||
