Skip to content

Commit 8c60b7b

Browse files
committed
src/internal.c and tests/api.c: fix clang-analyzer-core.NullPointerArithms.
1 parent 9b90ea8 commit 8c60b7b

2 files changed

Lines changed: 45 additions & 30 deletions

File tree

src/internal.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34022,9 +34022,11 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3402234022
{
3402334023
#ifdef HAVE_CURVE25519
3402434024
if (ssl->peerX25519KeyPresent) {
34025-
ret = X25519SharedSecret(ssl,
34025+
ret = X25519SharedSecret(
34026+
ssl,
3402634027
(curve25519_key*)ssl->hsKey, ssl->peerX25519Key,
34027-
args->output + OPAQUE8_LEN, &args->length,
34028+
args->output ? args->output + OPAQUE8_LEN : NULL,
34029+
&args->length,
3402834030
ssl->arrays->preMasterSecret + OPAQUE16_LEN,
3402934031
&ssl->arrays->preMasterSz,
3403034032
WOLFSSL_CLIENT_END
@@ -34043,9 +34045,11 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3404334045
#endif
3404434046
#ifdef HAVE_CURVE448
3404534047
if (ssl->peerX448KeyPresent) {
34046-
ret = X448SharedSecret(ssl,
34048+
ret = X448SharedSecret(
34049+
ssl,
3404734050
(curve448_key*)ssl->hsKey, ssl->peerX448Key,
34048-
args->output + OPAQUE8_LEN, &args->length,
34051+
args->output ? args->output + OPAQUE8_LEN : NULL,
34052+
&args->length,
3404934053
ssl->arrays->preMasterSecret + OPAQUE16_LEN,
3405034054
&ssl->arrays->preMasterSz,
3405134055
WOLFSSL_CLIENT_END
@@ -34062,9 +34066,11 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3406234066
break;
3406334067
}
3406434068
#endif
34065-
ret = EccSharedSecret(ssl,
34069+
ret = EccSharedSecret(
34070+
ssl,
3406634071
(ecc_key*)ssl->hsKey, ssl->peerEccKey,
34067-
args->output + OPAQUE8_LEN, &args->length,
34072+
args->output ? args->output + OPAQUE8_LEN : NULL,
34073+
&args->length,
3406834074
ssl->arrays->preMasterSecret + OPAQUE16_LEN,
3406934075
&ssl->arrays->preMasterSz,
3407034076
WOLFSSL_CLIENT_END
@@ -34090,9 +34096,11 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3409034096

3409134097
#ifdef HAVE_CURVE25519
3409234098
if (ssl->peerX25519KeyPresent) {
34093-
ret = X25519SharedSecret(ssl,
34099+
ret = X25519SharedSecret(
34100+
ssl,
3409434101
(curve25519_key*)ssl->hsKey, ssl->peerX25519Key,
34095-
args->encSecret + OPAQUE8_LEN, &args->encSz,
34102+
args->encSecret ? args->encSecret + OPAQUE8_LEN : NULL,
34103+
&args->encSz,
3409634104
ssl->arrays->preMasterSecret,
3409734105
&ssl->arrays->preMasterSz,
3409834106
WOLFSSL_CLIENT_END
@@ -34111,9 +34119,11 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3411134119
#endif
3411234120
#ifdef HAVE_CURVE448
3411334121
if (ssl->peerX448KeyPresent) {
34114-
ret = X448SharedSecret(ssl,
34122+
ret = X448SharedSecret(
34123+
ssl,
3411534124
(curve448_key*)ssl->hsKey, ssl->peerX448Key,
34116-
args->encSecret + OPAQUE8_LEN, &args->encSz,
34125+
args->encSecret ? args->encSecret + OPAQUE8_LEN : NULL,
34126+
&args->encSz,
3411734127
ssl->arrays->preMasterSecret,
3411834128
&ssl->arrays->preMasterSz,
3411934129
WOLFSSL_CLIENT_END
@@ -34134,12 +34144,14 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3413434144
peerKey = (ssl->specs.static_ecdh) ?
3413534145
ssl->peerEccDsaKey : ssl->peerEccKey;
3413634146

34137-
ret = EccSharedSecret(ssl,
34138-
(ecc_key*)ssl->hsKey, peerKey,
34139-
args->encSecret + OPAQUE8_LEN, &args->encSz,
34140-
ssl->arrays->preMasterSecret,
34141-
&ssl->arrays->preMasterSz,
34142-
WOLFSSL_CLIENT_END);
34147+
ret = EccSharedSecret(
34148+
ssl,
34149+
(ecc_key*)ssl->hsKey, peerKey,
34150+
args->encSecret ? args->encSecret + OPAQUE8_LEN : NULL,
34151+
&args->encSz,
34152+
ssl->arrays->preMasterSecret,
34153+
&ssl->arrays->preMasterSz,
34154+
WOLFSSL_CLIENT_END);
3414334155

3414434156
if (!ssl->specs.static_ecdh
3414534157
#ifdef WOLFSSL_ASYNC_CRYPT

tests/api.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36905,6 +36905,7 @@ static int test_wolfSSL_PKCS7_sign(void)
3690536905
flags = PKCS7_BINARY | PKCS7_DETACHED;
3690636906
ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
3690736907
ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
36908+
ExpectNotNull(out);
3690836909

3690936910
/* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
3691036911
ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
@@ -36924,14 +36925,16 @@ static int test_wolfSSL_PKCS7_sign(void)
3692436925
p7Ver->contentSz = sizeof(data);
3692536926
}
3692636927
/* test for streaming */
36927-
ret = -1;
36928-
for (z = 0; z < outLen && ret != 0; z++) {
36929-
ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
36930-
if (ret < 0){
36931-
ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
36928+
if (EXPECT_SUCCESS()) {
36929+
ret = -1;
36930+
for (z = 0; z < outLen && ret != 0; z++) {
36931+
ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
36932+
if (ret < 0){
36933+
ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
36934+
}
3693236935
}
36936+
ExpectIntEQ(ret, 0);
3693336937
}
36934-
ExpectIntEQ(ret, 0);
3693536938
wc_PKCS7_Free(p7Ver);
3693636939
p7Ver = NULL;
3693736940
#endif /* !NO_PKCS7_STREAM */
@@ -36943,7 +36946,6 @@ static int test_wolfSSL_PKCS7_sign(void)
3694336946
PKCS7_free(p7Ver);
3694436947
p7Ver = NULL;
3694536948

36946-
ExpectNotNull(out);
3694736949
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
3694836950
out = NULL;
3694936951
PKCS7_free(p7);
@@ -36983,15 +36985,16 @@ static int test_wolfSSL_PKCS7_sign(void)
3698336985
p7Ver->contentSz = sizeof(data);
3698436986
}
3698536987
/* test for streaming */
36986-
ret = -1;
36987-
for (z = 0; z < outLen && ret != 0; z++) {
36988-
ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
36989-
if (ret < 0){
36990-
ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
36988+
if (EXPECT_SUCCESS()) {
36989+
ret = -1;
36990+
for (z = 0; z < outLen && ret != 0; z++) {
36991+
ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
36992+
if (ret < 0){
36993+
ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
36994+
}
3699136995
}
36996+
ExpectIntEQ(ret, 0);
3699236997
}
36993-
ExpectIntEQ(ret, 0);
36994-
ExpectNotNull(out);
3699536998
wc_PKCS7_Free(p7Ver);
3699636999
p7Ver = NULL;
3699737000
#endif /* !NO_PKCS7_STREAM */

0 commit comments

Comments
 (0)