Skip to content

Commit a38277a

Browse files
committed
Fix GH-17346: PDOStatement::$queryString "readonly" is not properly implemented
We shouldn't use a cache slot while writing as it would allow to bypass the custom "read only" behaviour. (Note that this is not a "real" readonly, it is more like a "writeonce")
1 parent f5240b6 commit a38277a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,7 @@ static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *val
19311931
zend_throw_error(NULL, "Property queryString is read only");
19321932
return value;
19331933
}
1934+
cache_slot = NULL;
19341935
}
19351936
return zend_std_write_property(object, name, value, cache_slot);
19361937
}

ext/pdo/tests/gh17346.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-17346 (PDOStatement::$queryString "readonly" is not properly implemented)
3+
--EXTENSIONS--
4+
pdo
5+
--SKIPIF--
6+
<?php
7+
$dir = getenv('REDIR_TEST_DIR');
8+
if (false != $dir) die('skip is driver independent');
9+
?>
10+
--FILE--
11+
<?php
12+
$stmt = new PDOStatement();
13+
try {
14+
for ($i = 0; $i < 10; $i++) {
15+
$stmt->queryString = (string) $i;
16+
}
17+
} catch (Error $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
var_dump($stmt);
21+
?>
22+
--EXPECTF--
23+
Property queryString is read only
24+
object(PDOStatement)#%d (1) {
25+
["queryString"]=>
26+
string(1) "0"
27+
}

0 commit comments

Comments
 (0)