Skip to content

Commit 57f416f

Browse files
Merge pull request #9961 from sebastian-carpenter/tls-ech-coverity
minor coverity fixes for tls ech code
2 parents 416072f + 47a24d7 commit 57f416f

3 files changed

Lines changed: 28 additions & 28 deletions

File tree

src/tls13.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5094,10 +5094,10 @@ static int EchCheckAcceptance(WOLFSSL* ssl, byte* label, word16 labelSz,
50945094
ret = EchCalcAcceptance(ssl, label, labelSz, input, acceptOffset, helloSz,
50955095
msgType == hello_retry_request, acceptConfirmation);
50965096

5097-
tmpHashes = ssl->hsHashes;
5098-
ssl->hsHashes = ssl->hsHashesEch;
5099-
51005097
if (ret == 0) {
5098+
tmpHashes = ssl->hsHashes;
5099+
ssl->hsHashes = ssl->hsHashesEch;
5100+
51015101
/* last 8 bytes must match the expand output */
51025102
ret = ConstantCompare(acceptConfirmation, input + acceptOffset,
51035103
ECH_ACCEPT_CONFIRMATION_SZ);
@@ -5126,9 +5126,10 @@ static int EchCheckAcceptance(WOLFSSL* ssl, byte* label, word16 labelSz,
51265126
FreeHandshakeHashes(ssl);
51275127
ssl->hsHashesEch = NULL;
51285128
}
5129+
5130+
ssl->hsHashes = tmpHashes;
51295131
}
51305132

5131-
ssl->hsHashes = tmpHashes;
51325133
return ret;
51335134
}
51345135
#endif /* HAVE_ECH */
@@ -6806,25 +6807,28 @@ static int EchWriteAcceptance(WOLFSSL* ssl, byte* label, word16 labelSz,
68066807
helloSz - headerSz, msgType == hello_retry_request,
68076808
output + acceptOffset);
68086809

6809-
tmpHashes = ssl->hsHashes;
6810-
ssl->hsHashes = ssl->hsHashesEch;
6810+
if (ret == 0) {
6811+
tmpHashes = ssl->hsHashes;
6812+
ssl->hsHashes = ssl->hsHashesEch;
68116813

6812-
/* after HRR, hsHashesEch must contain:
6813-
* message_hash(ClientHelloInner1) || HRR (actual, not zeros) */
6814-
if (ret == 0 && msgType == hello_retry_request) {
6815-
ret = HashRaw(ssl, output, helloSz);
6816-
}
6817-
/* normal TLS code will calculate transcript of ServerHello */
6818-
else if (ret == 0) {
6819-
ssl->options.echAccepted = 1;
6814+
/* after HRR, hsHashesEch must contain:
6815+
* message_hash(ClientHelloInner1) || HRR (actual, not zeros) */
6816+
if (msgType == hello_retry_request) {
6817+
ret = HashRaw(ssl, output, helloSz);
6818+
}
6819+
/* normal TLS code will calculate transcript of ServerHello */
6820+
else {
6821+
ssl->options.echAccepted = 1;
6822+
6823+
ssl->hsHashes = tmpHashes;
6824+
FreeHandshakeHashes(ssl);
6825+
tmpHashes = ssl->hsHashesEch;
6826+
ssl->hsHashesEch = NULL;
6827+
}
68206828

68216829
ssl->hsHashes = tmpHashes;
6822-
FreeHandshakeHashes(ssl);
6823-
tmpHashes = ssl->hsHashesEch;
6824-
ssl->hsHashesEch = NULL;
68256830
}
68266831

6827-
ssl->hsHashes = tmpHashes;
68286832
return ret;
68296833
}
68306834
#endif

tests/api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13818,7 +13818,8 @@ static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
1381813818
if (callbacks->ctx_ready)
1381913819
callbacks->ctx_ready(ctx);
1382013820

13821-
AssertNotNull(ssl = wolfSSL_new(ctx));
13821+
ssl = wolfSSL_new(ctx);
13822+
AssertNotNull(ssl);
1382213823

1382313824
/* set the sni for the server */
1382413825
AssertIntEQ(WOLFSSL_SUCCESS,

wolfcrypt/src/hpke.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static int wc_HpkeLabeledExtract(Hpke* hpke, byte* suite_id,
472472
}
473473

474474
/* check that sum of len's will not overflow */
475-
remaining = MAX_HPKE_LABEL_SZ;
475+
remaining = (word32)MAX_HPKE_LABEL_SZ;
476476
if ((word32)HPKE_VERSION_STR_LEN > remaining) {
477477
return BUFFER_E;
478478
}
@@ -541,16 +541,11 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len,
541541
}
542542

543543
/* check that sum of len's will not overflow */
544-
remaining = MAX_HPKE_LABEL_SZ;
545-
if (2U > remaining){
544+
remaining = (word32)MAX_HPKE_LABEL_SZ;
545+
if (2U + (word32)HPKE_VERSION_STR_LEN > remaining) {
546546
return BUFFER_E;
547547
}
548-
remaining -= 2U;
549-
550-
if ((word32)HPKE_VERSION_STR_LEN > remaining) {
551-
return BUFFER_E;
552-
}
553-
remaining -= (word32)HPKE_VERSION_STR_LEN;
548+
remaining -= 2U + (word32)HPKE_VERSION_STR_LEN;
554549

555550
if (suite_id_len > remaining) {
556551
return BUFFER_E;

0 commit comments

Comments
 (0)