Skip to content

Commit 5bb8b3f

Browse files
committed
src/pk_ec.c: in wolfSSL_ECDSA_SIG_new(), mitigate false-positive nullPointerOutOfMemory by returning immediately if initial XMALLOC() fails.
1 parent aa4b84f commit 5bb8b3f

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/pk_ec.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4898,18 +4898,16 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_SIG_new(void)
48984898
DYNAMIC_TYPE_ECC);
48994899
if (sig == NULL) {
49004900
WOLFSSL_MSG("wolfSSL_ECDSA_SIG_new malloc ECDSA signature failure");
4901-
err = 1;
4901+
return NULL;
49024902
}
49034903

4904-
if (!err) {
4905-
/* Set s to NULL in case of error. */
4906-
sig->s = NULL;
4907-
/* Allocate BN into r. */
4908-
sig->r = wolfSSL_BN_new();
4909-
if (sig->r == NULL) {
4910-
WOLFSSL_MSG("wolfSSL_ECDSA_SIG_new malloc ECDSA r failure");
4911-
err = 1;
4912-
}
4904+
/* Set s to NULL in case of error. */
4905+
sig->s = NULL;
4906+
/* Allocate BN into r. */
4907+
sig->r = wolfSSL_BN_new();
4908+
if (sig->r == NULL) {
4909+
WOLFSSL_MSG("wolfSSL_ECDSA_SIG_new malloc ECDSA r failure");
4910+
err = 1;
49134911
}
49144912
if (!err) {
49154913
/* Allocate BN into s. */
@@ -4920,7 +4918,7 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_SIG_new(void)
49204918
}
49214919
}
49224920

4923-
if (err && (sig != NULL)) {
4921+
if (err) {
49244922
/* Dispose of allocated memory. */
49254923
wolfSSL_ECDSA_SIG_free(sig);
49264924
sig = NULL;

0 commit comments

Comments
 (0)