Skip to content

Commit 6fa793d

Browse files
committed
bn: avoid ossl_bn_new(NULL)
Currently, calling ossl_bn_new() with a NULL argument allocates a new OpenSSL::BN instance representing 0. This behavior is confusing. Raise an exception if this is attempted, instead.
1 parent 54d26ed commit 6fa793d

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

ext/openssl/ossl_bn.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ ossl_bn_new(const BIGNUM *bn)
6161
VALUE obj;
6262

6363
obj = NewBN(cBN);
64-
newbn = bn ? BN_dup(bn) : BN_new();
65-
if (!newbn) {
66-
ossl_raise(eBNError, NULL);
67-
}
64+
newbn = BN_dup(bn);
65+
if (!newbn)
66+
ossl_raise(eBNError, "BN_dup");
6867
SetBN(obj, newbn);
6968

7069
return obj;

ext/openssl/ossl_pkey_ec.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,10 @@ static VALUE ossl_ec_group_get_order(VALUE self)
805805
{
806806
VALUE bn_obj;
807807
BIGNUM *bn;
808-
EC_GROUP *group = NULL;
808+
EC_GROUP *group;
809809

810810
GetECGroup(self, group);
811-
812-
bn_obj = ossl_bn_new(NULL);
811+
bn_obj = ossl_bn_new(BN_value_one());
813812
bn = GetBNPtr(bn_obj);
814813

815814
if (EC_GROUP_get_order(group, bn, ossl_bn_ctx) != 1)
@@ -830,11 +829,10 @@ static VALUE ossl_ec_group_get_cofactor(VALUE self)
830829
{
831830
VALUE bn_obj;
832831
BIGNUM *bn;
833-
EC_GROUP *group = NULL;
832+
EC_GROUP *group;
834833

835834
GetECGroup(self, group);
836-
837-
bn_obj = ossl_bn_new(NULL);
835+
bn_obj = ossl_bn_new(BN_value_one());
838836
bn = GetBNPtr(bn_obj);
839837

840838
if (EC_GROUP_get_cofactor(group, bn, ossl_bn_ctx) != 1)

0 commit comments

Comments
 (0)