Skip to content

Commit 2abbab2

Browse files
authored
Merge pull request #8082 from SparkiDev/bn_bin2bn_fix
BN API: fix BN_bin2bn to handle NULL data properly
2 parents db6a2cc + 64a9e6f commit 2abbab2

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/ssl_bn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,14 @@ WOLFSSL_BIGNUM* wolfSSL_BN_bin2bn(const unsigned char* data, int len,
516516
ret = NULL;
517517
}
518518
else {
519-
/* Don't free bn as we may be returning it. */
519+
/* Don't free bn as we are returning it. */
520520
bn = NULL;
521521
}
522522
}
523523
else if (data == NULL) {
524524
wolfSSL_BN_zero(ret);
525+
/* Don't free bn as we are returning it. */
526+
bn = NULL;
525527
}
526528
}
527529

tests/api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61624,6 +61624,11 @@ static int test_wolfSSL_BN_enc_dec(void)
6162461624
ExpectNull(BN_bn2dec(NULL));
6162561625
ExpectNull(BN_bn2dec(&emptyBN));
6162661626

61627+
ExpectNotNull(c = BN_bin2bn(NULL, 0, NULL));
61628+
BN_clear(c);
61629+
BN_free(c);
61630+
c = NULL;
61631+
6162761632
ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
6162861633
BN_free(a);
6162961634
a = NULL;

0 commit comments

Comments
 (0)