Skip to content

Commit ef1bd8f

Browse files
committed
Fixed bug #70389 (PDO constructor changes unrelated variables)
1 parent 00eebd7 commit ef1bd8f

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ PHP NEWS
1010
. Fixed bug #55259 (openssl extension does not get the DH parameters from
1111
DH key resource). (Jakub Zelenka)
1212

13+
- PDO:
14+
- Fixed bug #70389 (PDO constructor changes unrelated variables). (Laruence)
15+
1316
- Standard:
1417
. Fixed bug #67131 (setcookie() conditional for empty values not met). (cmb)
1518

ext/pdo/pdo_dbh.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,14 @@ static PHP_METHOD(PDO, dbh_constructor)
289289
Z_STRVAL_PP(v));
290290
is_persistent = 1;
291291
} else {
292-
convert_to_long_ex(v);
293-
is_persistent = Z_LVAL_PP(v) ? 1 : 0;
292+
if (Z_TYPE_PP(v) != IS_LONG) {
293+
zval tmp = **v;
294+
zval_copy_ctor(&tmp);
295+
convert_to_long(&tmp);
296+
is_persistent = Z_LVAL(tmp)? 1 : 0;
297+
} else {
298+
is_persistent = Z_LVAL_PP(v)? 1 : 0;
299+
}
294300
plen = spprintf(&hashkey, 0, "PDO:DBH:DSN=%s:%s:%s", data_source,
295301
username ? username : "",
296302
password ? password : "");

ext/pdo/php_pdo_driver.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ static inline long pdo_attr_lval(zval *options, enum pdo_attribute_type option_n
197197
zval **v;
198198

199199
if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
200-
convert_to_long_ex(v);
200+
if (Z_TYPE_PP(v) != IS_LONG) {
201+
zval tmp = **v;
202+
zval_copy_ctor(&tmp);
203+
convert_to_long(&tmp);
204+
return Z_LVAL(tmp);
205+
}
201206
return Z_LVAL_PP(v);
202207
}
203208
return defval;
@@ -207,7 +212,12 @@ static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type optio
207212
zval **v;
208213

209214
if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) {
210-
convert_to_string_ex(v);
215+
if (Z_TYPE_PP(v) != IS_STRING) {
216+
zval tmp = **v;
217+
zval_copy_ctor(&tmp);
218+
convert_to_string(&tmp);
219+
return Z_STRVAL(tmp);
220+
}
211221
return estrndup(Z_STRVAL_PP(v), Z_STRLEN_PP(v));
212222
}
213223
return defval ? estrdup(defval) : NULL;

ext/pdo_mysql/tests/bug70389.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #70389 (PDO constructor changes unrelated variables)
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require(dirname(__FILE__). DIRECTORY_SEPARATOR . 'config.inc');
12+
$flags = [
13+
PDO::MYSQL_ATTR_FOUND_ROWS => true,
14+
PDO::MYSQL_ATTR_LOCAL_INFILE => true,
15+
PDO::ATTR_PERSISTENT => true,
16+
];
17+
18+
$std = new StdClass();
19+
$std->flags = $flags;
20+
21+
new PDO(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, $flags);
22+
var_dump($flags);
23+
24+
?>
25+
--EXPECTF--
26+
array(3) {
27+
[1005]=>
28+
bool(true)
29+
[1001]=>
30+
bool(true)
31+
[12]=>
32+
bool(true)
33+
}

0 commit comments

Comments
 (0)