Skip to content

Commit a347b0b

Browse files
committed
Fixed bug #70949 (SQL Result Sets With NULL Can Cause Fatal Memory Errors)
1 parent b0f472b commit a347b0b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ PHP NEWS
2020
from an array. (Bob)
2121

2222
- Mysqlnd:
23+
. Fixed bug #70949 (SQL Result Sets With NULL Can Cause Fatal Memory Errors).
24+
(Laruence)
2325
. Fixed bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction).
2426
(Laruence)
2527

ext/mysqli/tests/bug70949.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Bug #70949 (SQL Result Sets With NULL Can Cause Fatal Memory Errors)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
require_once("connect.inc");
8+
if (!$IS_MYSQLND) {
9+
die("skip mysqlnd only test");
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
require_once("connect.inc");
15+
$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
16+
17+
$mysql->query("DROP TABLE IF EXISTS bug70949");
18+
$mysql->query("CREATE TABLE bug70949(name varchar(255))");
19+
$mysql->query("INSERT INTO bug70949 VALUES ('dummy'),(NULL),('foo'),('bar')");
20+
21+
$sql = "select * from bug70949";
22+
23+
if ($stmt = $mysql->prepare($sql))
24+
{
25+
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY);
26+
27+
if ($stmt->bind_result($name)) {
28+
{
29+
if ($stmt->execute())
30+
{
31+
while ($stmt->fetch())
32+
{
33+
var_dump($name);
34+
}
35+
}
36+
}
37+
38+
$stmt->free_result();
39+
$stmt->close();
40+
}
41+
42+
43+
$mysql->close();
44+
}
45+
46+
?>
47+
--CLEAN--
48+
<?php
49+
require_once("connect.inc");
50+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
51+
printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
52+
53+
if (!mysqli_query($link, "DROP TABLE IF EXISTS bug70949"))
54+
printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
55+
56+
mysqli_close($link);
57+
?>
58+
--EXPECT--
59+
string(5) "dummy"
60+
NULL
61+
string(3) "foo"
62+
string(3) "bar"

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,8 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, unsigned int f
11151115
ZVAL_COPY_VALUE(result, data);
11161116
/* copied data, thus also the ownership. Thus null data */
11171117
ZVAL_NULL(data);
1118+
} else {
1119+
ZVAL_NULL(result);
11181120
}
11191121
}
11201122
}

0 commit comments

Comments
 (0)