1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ext/openssl/ossl_bn.c: fix implicit conversion

* ext/openssl/ossl_bn.c (ossl_bn_initialize): fix precision loss by
  implicit conversion.

* ext/openssl/ossl_bn.c (ossl_bn_initialize): check Bignum overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-04-25 07:57:17 +00:00
parent 91fb5bc889
commit adb492406c

View file

@ -125,7 +125,7 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
long i;
unsigned char *bin = (unsigned char*)ALLOC_N(long, 1);
long n = FIX2LONG(str);
unsigned long un = abs(n);
unsigned long un = labs(n);
for (i = sizeof(VALUE) - 1; 0 <= i; i--) {
bin[i] = un&0xff;
@ -153,7 +153,7 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
}
GetBN(self, bn);
if (!BN_bin2bn(bin, sizeof(BDIGIT)*RBIGNUM_LEN(str), bn)) {
if (!BN_bin2bn(bin, (int)sizeof(BDIGIT)*RBIGNUM_LENINT(str), bn)) {
ossl_raise(eBNError, NULL);
}
if (!RBIGNUM_SIGN(str)) BN_set_negative(bn, 1);