summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/bn/bn_lib.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c
index 4fe6ce071a..9d665c26fc 100644
--- a/crypto/bn/bn_lib.c
+++ b/crypto/bn/bn_lib.c
@@ -447,6 +447,15 @@ static BIGNUM *bin2bn(const unsigned char *s, int len, BIGNUM *ret,
bn_check_top(ret);
/*
+ * If the input has no bits, the number is considered zero.
+ * This makes calls with s==NULL and len==0 safe.
+ */
+ if (len == 0) {
+ BN_clear(ret);
+ return ret;
+ }
+
+ /*
* The loop that does the work iterates from least to most
* significant BIGNUM chunk, so we adapt parameters to transfer
* input bytes accordingly.