diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-10 12:57:39 +0000 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2021-09-26 19:17:28 +0900 |
commit | 3e9a4b65fae8f3f845bca39d798edaf45242815e (patch) | |
tree | a673205ad12dd87ec975218c8f604973125a8365 | |
parent | c4219454d0a0c7dfbd7f63aa5715104d3f488b02 (diff) | |
download | ruby-openssl-3e9a4b65fae8f3f845bca39d798edaf45242815e.tar.gz |
ext/openssl/ossl_bn.c (ossl_bn_initialize): get rid of SEGV
[ This is a backport to the 2.1 branch. ]
OpenSSL::BN.new(nil, 2) dumped core.
[ruby-core:92231] [Bug #15760]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(cherry picked from commit ruby/ruby@82632d4c0c117a7728293ff955e3527487230bc1)
-rw-r--r-- | ext/openssl/ossl_bn.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index ba5f38b2..e3846d2d 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -187,6 +187,7 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self) BIGNUM *bn; VALUE str, bs; int base = 10; + char *ptr; if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) { base = NUM2INT(bs); @@ -213,12 +214,14 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self) GetBN(self, bn); switch (base) { case 0: - if (!BN_mpi2bn((unsigned char *)StringValuePtr(str), RSTRING_LENINT(str), bn)) { + ptr = StringValuePtr(str); + if (!BN_mpi2bn((unsigned char *)ptr, RSTRING_LENINT(str), bn)) { ossl_raise(eBNError, NULL); } break; case 2: - if (!BN_bin2bn((unsigned char *)StringValuePtr(str), RSTRING_LENINT(str), bn)) { + ptr = StringValuePtr(str); + if (!BN_bin2bn((unsigned char *)ptr, RSTRING_LENINT(str), bn)) { ossl_raise(eBNError, NULL); } break; |