Skip to content

Commit 64a9e6f

Browse files
committed
BN API: fix BN_bin2bn to handle NULL data properly
BN_bin2bn was freeing the BN and returning it. Added test for this.
1 parent 0f8b4db commit 64a9e6f

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
@@ -61606,6 +61606,11 @@ static int test_wolfSSL_BN_enc_dec(void)
6160661606
ExpectNull(BN_bn2dec(NULL));
6160761607
ExpectNull(BN_bn2dec(&emptyBN));
6160861608

61609+
ExpectNotNull(c = BN_bin2bn(NULL, 0, NULL));
61610+
BN_clear(c);
61611+
BN_free(c);
61612+
c = NULL;
61613+
6160961614
ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
6161061615
BN_free(a);
6161161616
ExpectNotNull(a = BN_new());

0 commit comments

Comments
 (0)