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