diff options
author | Xinchen Hui <laruence@gmail.com> | 2015-08-30 05:02:13 -0700 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2015-08-30 05:02:38 -0700 |
commit | ef1bd8f0e6f88b1d123cea1c0b5079cfde7f90df (patch) | |
tree | e78a20e0353ecb1c76bda4169a98c2099981da11 | |
parent | 00eebd7a477f8076a5fbb4712f380c8214952bdf (diff) | |
download | php-git-ef1bd8f0e6f88b1d123cea1c0b5079cfde7f90df.tar.gz |
Fixed bug #70389 (PDO constructor changes unrelated variables)
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/pdo/pdo_dbh.c | 10 | ||||
-rw-r--r-- | ext/pdo/php_pdo_driver.h | 14 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/bug70389.phpt | 33 |
4 files changed, 56 insertions, 4 deletions
@@ -10,6 +10,9 @@ PHP NEWS . Fixed bug #55259 (openssl extension does not get the DH parameters from DH key resource). (Jakub Zelenka) +- PDO: + - Fixed bug #70389 (PDO constructor changes unrelated variables). (Laruence) + - Standard: . Fixed bug #67131 (setcookie() conditional for empty values not met). (cmb) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 6857a9b5e6..c7d7e0774f 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -289,8 +289,14 @@ static PHP_METHOD(PDO, dbh_constructor) Z_STRVAL_PP(v)); is_persistent = 1; } else { - convert_to_long_ex(v); - is_persistent = Z_LVAL_PP(v) ? 1 : 0; + if (Z_TYPE_PP(v) != IS_LONG) { + zval tmp = **v; + zval_copy_ctor(&tmp); + convert_to_long(&tmp); + is_persistent = Z_LVAL(tmp)? 1 : 0; + } else { + is_persistent = Z_LVAL_PP(v)? 1 : 0; + } plen = spprintf(&hashkey, 0, "PDO:DBH:DSN=%s:%s:%s", data_source, username ? username : "", password ? password : ""); diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index d651345678..44082df498 100644 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -197,7 +197,12 @@ static inline long pdo_attr_lval(zval *options, enum pdo_attribute_type option_n zval **v; if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) { - convert_to_long_ex(v); + if (Z_TYPE_PP(v) != IS_LONG) { + zval tmp = **v; + zval_copy_ctor(&tmp); + convert_to_long(&tmp); + return Z_LVAL(tmp); + } return Z_LVAL_PP(v); } return defval; @@ -207,7 +212,12 @@ static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type optio zval **v; if (options && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(options), option_name, (void**)&v)) { - convert_to_string_ex(v); + if (Z_TYPE_PP(v) != IS_STRING) { + zval tmp = **v; + zval_copy_ctor(&tmp); + convert_to_string(&tmp); + return Z_STRVAL(tmp); + } return estrndup(Z_STRVAL_PP(v), Z_STRLEN_PP(v)); } return defval ? estrdup(defval) : NULL; diff --git a/ext/pdo_mysql/tests/bug70389.phpt b/ext/pdo_mysql/tests/bug70389.phpt new file mode 100644 index 0000000000..b9084f63e3 --- /dev/null +++ b/ext/pdo_mysql/tests/bug70389.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #70389 (PDO constructor changes unrelated variables) +--SKIPIF-- +<?php +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +MySQLPDOTest::skip(); +?> +--FILE-- +<?php +require(dirname(__FILE__). DIRECTORY_SEPARATOR . 'config.inc'); +$flags = [ + PDO::MYSQL_ATTR_FOUND_ROWS => true, + PDO::MYSQL_ATTR_LOCAL_INFILE => true, + PDO::ATTR_PERSISTENT => true, +]; + +$std = new StdClass(); +$std->flags = $flags; + +new PDO(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, $flags); +var_dump($flags); + +?> +--EXPECTF-- +array(3) { + [1005]=> + bool(true) + [1001]=> + bool(true) + [12]=> + bool(true) +} |