From fb582f645245fc89845f9f3046bdfa50aaffcb2b Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 25 Nov 2026 18:06:26 +0100 Subject: [PATCH 1/3] Fix race in ghsa-r6x9-5r99-36j7 tests Closing the connection makes mysqli send a COM_QUIT packet, but we don't wait for it in $process->terminate() unless $wait is set to true. Avoid by not closing the connection, as otherwise the test expectation changes. --- ext/mysqli/tests/ghsa-h35g-vwh6-m678-def.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-2-bytes.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-8-bytes.phpt | 2 -- ...sa-r6x9-5r99-36j7-auth-packet-affected-rows-null-length.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-cached-sha2-switch-unterminated.phpt | 2 -- ext/mysqli/tests/ghsa-r6x9-5r99-36j7-query-row-eof-short.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt | 2 -- .../tests/ghsa-r6x9-5r99-36j7-stmt-response-row-status.phpt | 2 -- .../tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt | 2 -- .../ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt | 2 -- .../tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt | 2 -- 12 files changed, 24 deletions(-) diff --git a/ext/mysqli/tests/ghsa-h35g-vwh6-m678-def.phpt b/ext/mysqli/tests/ghsa-h35g-vwh6-m678-def.phpt index 0883962321d2..dfdd02728ddd 100644 --- a/ext/mysqli/tests/ghsa-h35g-vwh6-m678-def.phpt +++ b/ext/mysqli/tests/ghsa-h35g-vwh6-m678-def.phpt @@ -25,8 +25,6 @@ if ($result) { var_dump(get_object_vars($all_fields[0])["def"]); } -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-2-bytes.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-2-bytes.phpt index 45d33cdf7fc1..cbfbf05ca5bb 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-2-bytes.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-2-bytes.phpt @@ -16,8 +16,6 @@ $process->wait(); $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ); echo "[*] connect_errno: ", $conn->connect_errno, "\n"; -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-8-bytes.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-8-bytes.phpt index 63233ad8291e..e6a976db0a42 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-8-bytes.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-8-bytes.phpt @@ -16,8 +16,6 @@ $process->wait(); $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ); echo "[*] connect_errno: ", $conn->connect_errno, "\n"; -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-null-length.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-null-length.phpt index 6a18f36d37c6..ee3a6a1238f5 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-null-length.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-auth-packet-affected-rows-null-length.phpt @@ -16,8 +16,6 @@ $process->wait(); $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ); echo "[*] connect_errno: ", $conn->connect_errno, "\n"; -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-cached-sha2-switch-unterminated.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-cached-sha2-switch-unterminated.phpt index 2554a46c5a00..316d9fc0d286 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-cached-sha2-switch-unterminated.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-cached-sha2-switch-unterminated.phpt @@ -20,8 +20,6 @@ $process->wait(); $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ); echo "[*] connect_errno: ", $conn->connect_errno, "\n"; -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-query-row-eof-short.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-query-row-eof-short.phpt index 685af9948ba3..b5446d5dea99 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-query-row-eof-short.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-query-row-eof-short.phpt @@ -23,8 +23,6 @@ if ($result->num_rows > 0) { var_dump($row); } } -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt index 44d61c244149..347ad3f79b7c 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt @@ -18,8 +18,6 @@ $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ) echo "[*] Preparing statement on the fake server...\n"; $conn->prepare("SELECT item FROM items"); -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt index 69756273b9a8..d0fe8e534950 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt @@ -18,8 +18,6 @@ $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ) echo "[*] Preparing statement on the fake server...\n"; $conn->prepare("SELECT item FROM items"); -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-row-status.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-row-status.phpt index 1c71da1cbbc4..4d72e7add5b6 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-row-status.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-row-status.phpt @@ -18,8 +18,6 @@ $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ) echo "[*] Preparing statement on the fake server...\n"; $conn->prepare("SELECT item FROM items"); -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt index e01dc3ff5c66..fc26ba0403b4 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt @@ -23,8 +23,6 @@ while ($row = $result->fetch_row()) { var_dump($row); } $stmt->close(); -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt index 8e86d4039879..66209fe53b1c 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt @@ -23,8 +23,6 @@ while ($row = $result->fetch_row()) { var_dump($row); } $stmt->close(); -$conn->close(); - $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt index 0b9335c42f4e..3d8b7b205143 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt @@ -23,8 +23,6 @@ while ($row = $result->fetch_row()) { var_dump($row); } $stmt->close(); -$conn->close(); - $process->terminate(); print "done!"; From 78bb5f7d89e35460ff8db5e318676fe775d7a75c Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 27 Nov 2026 01:22:09 +0100 Subject: [PATCH 2/3] Implement feedback Co-authored-by: Kamil Tekiela --- ext/mysqli/tests/fake_server.inc | 4 ---- .../ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt | 4 +++- ...ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt | 4 +++- .../tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt | 1 - .../ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt | 1 - .../tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt | 1 - 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ext/mysqli/tests/fake_server.inc b/ext/mysqli/tests/fake_server.inc index ff49ae896066..82b20de26590 100644 --- a/ext/mysqli/tests/fake_server.inc +++ b/ext/mysqli/tests/fake_server.inc @@ -1373,8 +1373,6 @@ function my_mysqli_test_stmt_response_row_over_read_status(my_mysqli_fake_server function my_mysqli_test_stmt_response_field_len_faulty(my_mysqli_fake_server_conn $conn): void { - $rh = $conn->packet_generator->server_stmt_execute_items_response(); - $conn->send_server_greetings(); $conn->read(); $conn->send_server_ok(); @@ -1385,8 +1383,6 @@ function my_mysqli_test_stmt_response_field_len_faulty(my_mysqli_fake_server_con $packets[2]->packet_length = '1f0000'; $conn->send($conn->packets_to_bytes($packets), "Stmt prepare items"); $conn->read(); - $conn->send($conn->packets_to_bytes($rh), "Malicious Stmt Response for fields [Extract heap through buffer over-read]"); - $conn->read(65536); } function my_mysqli_test_stmt_response_field_len_premature(my_mysqli_fake_server_conn $conn): void diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt index 347ad3f79b7c..8ce911893d2f 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-faulty.phpt @@ -18,7 +18,7 @@ $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ) echo "[*] Preparing statement on the fake server...\n"; $conn->prepare("SELECT item FROM items"); -$process->terminate(); +$process->terminate(true); print "done!"; ?> @@ -33,4 +33,6 @@ print "done!"; [*] Sending - Stmt prepare items: 0c0000010001000000010000000000003000000203646566087068705f74657374056974656d73056974656d73046974656dfe6974656d0ce000c8000000fd01100000001f000003fe00000200 Warning: mysqli::prepare(): Protocol error. Server sent NULL_LENGTH. The server is faulty in %s on line %d +[*] Received: 050000001901000000 +[*] Server finished done! diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt index d0fe8e534950..9bc0fcc3f719 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-response-field-len-premature.phpt @@ -18,7 +18,7 @@ $conn = new mysqli( $servername, $username, $password, "", $process->getPort() ) echo "[*] Preparing statement on the fake server...\n"; $conn->prepare("SELECT item FROM items"); -$process->terminate(); +$process->terminate(true); print "done!"; ?> @@ -37,4 +37,6 @@ Warning: mysqli::prepare(): Protocol error. Server sent false length. Expected 1 Warning: mysqli::prepare(): Premature end of data (mysqlnd_wireprotocol.c:%d) in %s on line %d Warning: mysqli::prepare(): Result set field packet shorter than expected in %s on line %d +[*] Received: 050000001901000000 +[*] Server finished done! diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt index fc26ba0403b4..a158a678b7eb 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt @@ -22,7 +22,6 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$stmt->close(); $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt index 66209fe53b1c..560ccb809a6a 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt @@ -22,7 +22,6 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$stmt->close(); $process->terminate(); print "done!"; diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt index 3d8b7b205143..58d2a4f4d476 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt @@ -22,7 +22,6 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$stmt->close(); $process->terminate(); print "done!"; From 4b2d6f830be289980b8e695505b8c48175f00440 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 27 Nov 2026 14:08:14 +0100 Subject: [PATCH 3/3] Fix another race $stmt will close during shutdown and send COM_STMT_CLOSE. If the process is already gone, the stream is too. --- .../ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt | 7 ++++++- ...ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt | 7 ++++++- .../ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt index a158a678b7eb..ecc92c798014 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-date.phpt @@ -22,7 +22,10 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$process->terminate(); +$stmt->close(); +$conn->close(); + +$process->terminate(true); print "done!"; ?> @@ -39,4 +42,6 @@ print "done!"; [*] Sending - Malicious Stmt Response for data datval [length too short]: 01000001023200000203646566087068705f74657374046461746104646174610673747276616c0673747276616c0ce000c8000000fd01100000003200000303646566087068705f74657374046461746104646174610664617476616c0664617476616c0c3f000a0000000a811000000005000004fe00002200090000050000047465737401de05000006fe00002200 Warning: mysqli_result::fetch_row(): Malformed server packet. Field length is too short for the field type in %s on line %d +[*] Received: 0500000019010000000100000001 +[*] Server finished done! diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt index 560ccb809a6a..797fb9145ee7 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-datetime.phpt @@ -22,7 +22,10 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$process->terminate(); +$stmt->close(); +$conn->close(); + +$process->terminate(true); print "done!"; ?> @@ -39,4 +42,6 @@ print "done!"; [*] Sending - Malicious Stmt Response for data dtival [length too short]: 01000001023200000203646566087068705f74657374046461746104646174610673747276616c0673747276616c0ce000c8000000fd01100000003200000303646566087068705f74657374046461746104646174610664746976616c0664746976616c0c3f00130000000c811000000005000004fe00002200090000050000047465737401de05000006fe00002200 Warning: mysqli_result::fetch_row(): Malformed server packet. Field length is too short for the field type in %s on line %d +[*] Received: 0500000019010000000100000001 +[*] Server finished done! diff --git a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt index 58d2a4f4d476..a1406c7a6824 100644 --- a/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt +++ b/ext/mysqli/tests/ghsa-r6x9-5r99-36j7-stmt-row-short-length-time.phpt @@ -22,7 +22,10 @@ $result = $stmt->get_result(); while ($row = $result->fetch_row()) { var_dump($row); } -$process->terminate(); +$stmt->close(); +$conn->close(); + +$process->terminate(true); print "done!"; ?> @@ -39,4 +42,6 @@ print "done!"; [*] Sending - Malicious Stmt Response for data timval [length too short]: 01000001023200000203646566087068705f74657374046461746104646174610673747276616c0673747276616c0ce000c8000000fd01100000003200000303646566087068705f74657374046461746104646174610674696d76616c0674696d76616c0c3f000a0000000b811000000005000004fe00002200090000050000047465737401de05000006fe00002200 Warning: mysqli_result::fetch_row(): Malformed server packet. Field length is too short for the field type in %s on line %d +[*] Received: 0500000019010000000100000001 +[*] Server finished done!