Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BN API: fix BN_bin2bn to handle NULL data properly #8082

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ssl_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,14 @@ WOLFSSL_BIGNUM* wolfSSL_BN_bin2bn(const unsigned char* data, int len,
ret = NULL;
}
else {
/* Don't free bn as we may be returning it. */
/* Don't free bn as we are returning it. */
bn = NULL;
}
}
else if (data == NULL) {
wolfSSL_BN_zero(ret);
/* Don't free bn as we are returning it. */
bn = NULL;
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -61606,6 +61606,11 @@ static int test_wolfSSL_BN_enc_dec(void)
ExpectNull(BN_bn2dec(NULL));
ExpectNull(BN_bn2dec(&emptyBN));

ExpectNotNull(c = BN_bin2bn(NULL, 0, NULL));
BN_clear(c);
BN_free(c);
c = NULL;

ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
BN_free(a);
ExpectNotNull(a = BN_new());
Expand Down
Loading