aboutsummaryrefslogtreecommitdiff
path: root/bignum.h
diff options
context:
space:
mode:
authorSatoshi Nakamoto <satoshin@gmx.com>2010-07-31 20:12:05 +0000
committerGavin Andresen <gavinandresen@gmail.com>2010-07-31 20:12:05 +0000
commit73aa262647ff9948eaf95e83236ec323347e95d0 (patch)
treee98a3a0ac2caa95047eb09ee7e8ea0ff817a0d9d /bignum.h
parente1cb7ce0177de72b00e06dc4c8fe1d414723a9e7 (diff)
fixed segfault in bignum.h, additional security limits, refactoringv0.3.7
-- version 0.3.7
Diffstat (limited to 'bignum.h')
-rw-r--r--bignum.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/bignum.h b/bignum.h
index 2dd6593b5a..450e809d3d 100644
--- a/bignum.h
+++ b/bignum.h
@@ -401,8 +401,16 @@ public:
CBigNum& operator>>=(unsigned int shift)
{
- // Note: BN_rshift segfaults on 64-bit ubuntu 9.10 if 2^shift is greater than the number,
- // tested OK on 64-bit ubuntu 10.4
+ // Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
+ // if built on ubuntu 9.04 or 9.10, probably depends on version of openssl
+ CBigNum a = 1;
+ a <<= shift;
+ if (BN_cmp(&a, this) > 0)
+ {
+ *this = 0;
+ return *this;
+ }
+
if (!BN_rshift(this, this, shift))
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
return *this;
@@ -511,10 +519,8 @@ inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
{
- CBigNum r;
- // Note: BN_rshift segfaults on 64-bit ubuntu 9.10 if 2^shift is greater than the number
- if (!BN_rshift(&r, &a, shift))
- throw bignum_error("CBigNum:operator>> : BN_rshift failed");
+ CBigNum r = a;
+ r >>= shift;
return r;
}