xref: /PHP-8.3/ext/mysqli/tests/gh8058.phpt (revision a21edc52)
1--TEST--
2GH-8058 (NULL pointer dereference in mysqlnd package (#81706))
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11require_once 'connect.inc';
12
13mysqli_report(MYSQLI_REPORT_OFF);
14$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
15
16// There should be no segfault due to NULL deref
17$stmt = $mysqli->prepare("select 1,2,3");
18$stmt->bind_result($a,$a,$a);
19$stmt->prepare("");
20$stmt->prepare("select ".str_repeat("'A',", 0x1201)."1");
21unset($stmt); // trigger dtor
22
23// There should be no memory leak
24$stmt = $mysqli->prepare("select 1,2,3");
25$stmt->bind_result($a,$a,$a);
26$stmt->prepare("");
27$stmt->prepare("select 1");
28unset($stmt); // trigger dtor
29
30mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
31$stmt = $mysqli->prepare("select 1,2,3");
32try {
33    // We expect an exception to be thrown
34    $stmt->prepare("");
35} catch (mysqli_sql_exception $e) {
36    var_dump($e->getMessage());
37}
38?>
39--EXPECT--
40string(15) "Query was empty"
41