Skip to content

Commit bb0ead8

Browse files
minor coverity fixes for tls ech
1 parent 0de6e8f commit bb0ead8

3 files changed

Lines changed: 28 additions & 34 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
@@ -13819,7 +13819,8 @@ static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
1381913819
if (callbacks->ctx_ready)
1382013820
callbacks->ctx_ready(ctx);
1382113821

13822-
AssertNotNull(ssl = wolfSSL_new(ctx));
13822+
ssl = wolfSSL_new(ctx);
13823+
AssertNotNull(ssl);
1382313824

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

wolfcrypt/src/hpke.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,8 @@ 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;
476-
if ((word32)HPKE_VERSION_STR_LEN > remaining) {
477-
return BUFFER_E;
478-
}
479-
remaining -= (word32)HPKE_VERSION_STR_LEN;
475+
wc_static_assert(MAX_HPKE_LABEL_SZ > HPKE_VERSION_STR_LEN);
476+
remaining = (word32)MAX_HPKE_LABEL_SZ - (word32)HPKE_VERSION_STR_LEN;
480477

481478
if (suite_id_len > remaining) {
482479
return BUFFER_E;
@@ -541,16 +538,8 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len,
541538
}
542539

543540
/* check that sum of len's will not overflow */
544-
remaining = MAX_HPKE_LABEL_SZ;
545-
if (2U > remaining){
546-
return BUFFER_E;
547-
}
548-
remaining -= 2U;
549-
550-
if ((word32)HPKE_VERSION_STR_LEN > remaining) {
551-
return BUFFER_E;
552-
}
553-
remaining -= (word32)HPKE_VERSION_STR_LEN;
541+
wc_static_assert(MAX_HPKE_LABEL_SZ > 2 + HPKE_VERSION_STR_LEN);
542+
remaining = (word32)MAX_HPKE_LABEL_SZ - 2U - (word32)HPKE_VERSION_STR_LEN;
554543

555544
if (suite_id_len > remaining) {
556545
return BUFFER_E;

0 commit comments

Comments
 (0)