Skip to content

Commit 348d75b

Browse files
Merge pull request #10098 from douzzer/20260328-test_wolfSSL_dtls_fragments-race-mitigation
20260328-test_wolfSSL_dtls_fragments-race-mitigation
2 parents b7e7e75 + 20d9ea0 commit 348d75b

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

tests/api.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24655,19 +24655,33 @@ static int test_wolfSSL_dtls_fragments(void)
2465524655

2465624656
test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
2465724657

24658-
ExpectFalse(func_cb_client.return_code);
24659-
ExpectFalse(func_cb_server.return_code);
24660-
24661-
/* The socket should be closed by the server resulting in a
24662-
* socket error, fatal error or reading a close notify alert */
24663-
if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
24664-
func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
24665-
func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
24666-
ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
24658+
/* If the client failed, check that the error it encountered was from
24659+
* the server aborting, resulting in a socket error, fatal error or
24660+
* reading a close notify alert.
24661+
*
24662+
* Under slow execution (e.g. valgrind + noasm), the server may
24663+
* still be processing fragments when the client completes its
24664+
* handshake and write, so the client may succeed -- in that
24665+
* case return_code is TEST_SUCCESS and these checks don't apply.
24666+
*/
24667+
if (func_cb_client.return_code == TEST_FAIL) {
24668+
if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
24669+
func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
24670+
func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
24671+
ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
24672+
}
2466724673
}
2466824674
/* Check the server returned an error indicating the msg buffer
24669-
* was full */
24670-
ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
24675+
* was full.
24676+
*
24677+
* Under slow execution (e.g. valgrind + noasm), the real handshake
24678+
* from wolfSSL_negotiate() may complete before enough spam fragments
24679+
* accumulate to trigger DTLS_TOO_MANY_FRAGMENTS_E. Accept both
24680+
* outcomes: server hit the fragment limit, or completed normally.
24681+
*/
24682+
if (func_cb_server.return_code == TEST_FAIL) {
24683+
ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
24684+
}
2467124685

2467224686
if (EXPECT_FAIL())
2467324687
break;

0 commit comments

Comments
 (0)