Skip to content

Commit 014abbc

Browse files
committed
Merge branch 'PHP-5.6'
Conflicts: ext/pdo/pdo_dbh.c ext/pdo/php_pdo_driver.h
2 parents d7cd2d7 + ef1bd8f commit 014abbc

File tree

5 files changed

+69
-31
lines changed

5 files changed

+69
-31
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
. Fixed bug #70386 (Can't compile on NetBSD because of missing WCONTINUED
2525
and WIFCONTINUED). (Matteo)
2626

27+
- PDO:
28+
- Fixed bug #70389 (PDO constructor changes unrelated variables). (Laruence)
29+
2730
- PDO_OCI:
2831
. Fixed bug #70308 (PDO::ATTR_PREFETCH is ignored). (Chris Jones)
2932

ext/pdo/pdo_dbh.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ static PHP_METHOD(PDO, dbh_constructor)
281281
Z_STRVAL_P(v));
282282
is_persistent = 1;
283283
} else {
284-
convert_to_long_ex(v);
285-
is_persistent = Z_LVAL_P(v) ? 1 : 0;
284+
is_persistent = zval_get_long(v) ? 1 : 0;
286285
plen = spprintf(&hashkey, 0, "PDO:DBH:DSN=%s:%s:%s", data_source,
287286
username ? username : "",
288287
password ? password : "");

ext/pdo/php_pdo_driver.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,18 @@ static inline zend_long pdo_attr_lval(zval *options, enum pdo_attribute_type opt
199199
zval *v;
200200

201201
if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
202-
convert_to_long_ex(v);
203-
return Z_LVAL_P(v);
202+
return zval_get_long(v);
204203
}
205204
return defval;
206205
}
207-
static inline char *pdo_attr_strval(zval *options, enum pdo_attribute_type option_name, char *defval)
206+
static inline zend_string *pdo_attr_strval(zval *options, enum pdo_attribute_type option_name, zend_string *defval)
208207
{
209208
zval *v;
210209

211210
if (options && (v = zend_hash_index_find(Z_ARRVAL_P(options), option_name))) {
212-
convert_to_string_ex(v);
213-
return estrndup(Z_STRVAL_P(v), Z_STRLEN_P(v));
211+
return zval_get_string(v);
214212
}
215-
return defval ? estrdup(defval) : NULL;
213+
return defval ? zend_string_copy(defval) : NULL;
216214
}
217215
/* }}} */
218216

ext/pdo_mysql/mysql_driver.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,12 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
602602
if (driver_options) {
603603
zend_long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30);
604604
zend_long local_infile = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0);
605-
char *init_cmd = NULL;
605+
zend_string *init_cmd = NULL;
606606
#ifndef PDO_USE_MYSQLND
607-
char *default_file = NULL, *default_group = NULL;
607+
zend_string *default_file = NULL, *default_group = NULL;
608608
#endif
609609
zend_long compress = 0;
610-
char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL;
610+
zend_string *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL;
611611
H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
612612

613613
H->emulate_prepare = pdo_attr_lval(driver_options,
@@ -658,32 +658,32 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
658658
#endif
659659
init_cmd = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_INIT_COMMAND, NULL);
660660
if (init_cmd) {
661-
if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)init_cmd)) {
662-
efree(init_cmd);
661+
if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)ZSTR_VAL(init_cmd))) {
662+
zend_string_release(init_cmd);
663663
pdo_mysql_error(dbh);
664664
goto cleanup;
665665
}
666-
efree(init_cmd);
666+
zend_string_release(init_cmd);
667667
}
668668
#ifndef PDO_USE_MYSQLND
669669
default_file = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_FILE, NULL);
670670
if (default_file) {
671-
if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)default_file)) {
672-
efree(default_file);
671+
if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)ZSTR_VAL(default_file))) {
672+
zend_string_release(default_file);
673673
pdo_mysql_error(dbh);
674674
goto cleanup;
675675
}
676-
efree(default_file);
676+
zend_string_release(default_file);
677677
}
678678

679-
default_group= pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL);
679+
default_group = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL);
680680
if (default_group) {
681-
if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)default_group)) {
682-
efree(default_group);
681+
if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)ZSTR_VAL(default_group))) {
682+
zend_string_release(default_group);
683683
pdo_mysql_error(dbh);
684684
goto cleanup;
685685
}
686-
efree(default_group);
686+
zend_string_release(default_group);
687687
}
688688
#endif
689689
compress = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_COMPRESS, 0);
@@ -701,34 +701,39 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
701701
ssl_cipher = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CIPHER, NULL);
702702

703703
if (ssl_key || ssl_cert || ssl_ca || ssl_capath || ssl_cipher) {
704-
mysql_ssl_set(H->server, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher);
704+
mysql_ssl_set(H->server,
705+
ssl_key? ZSTR_VAL(ssl_key) : NULL,
706+
ssl_cert? ZSTR_VAL(ssl_cert) : NULL,
707+
ssl_ca? ZSTR_VAL(ssl_ca) : NULL,
708+
ssl_capath? ZSTR_VAL(ssl_capath) : NULL,
709+
ssl_cipher? ZSTR_VAL(ssl_cipher) : NULL);
705710
if (ssl_key) {
706-
efree(ssl_key);
711+
zend_string_release(ssl_key);
707712
}
708713
if (ssl_cert) {
709-
efree(ssl_cert);
714+
zend_string_release(ssl_cert);
710715
}
711716
if (ssl_ca) {
712-
efree(ssl_ca);
717+
zend_string_release(ssl_ca);
713718
}
714719
if (ssl_capath) {
715-
efree(ssl_capath);
720+
zend_string_release(ssl_capath);
716721
}
717722
if (ssl_cipher) {
718-
efree(ssl_cipher);
723+
zend_string_release(ssl_cipher);
719724
}
720725
}
721726

722727
#if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
723728
{
724-
char *public_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY, NULL);
729+
zend_string *public_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY, NULL);
725730
if (public_key) {
726-
if (mysql_options(H->server, MYSQL_SERVER_PUBLIC_KEY, public_key)) {
731+
if (mysql_options(H->server, MYSQL_SERVER_PUBLIC_KEY, ZSTR_VAL(public_key))) {
727732
pdo_mysql_error(dbh);
728-
efree(public_key);
733+
zend_string_release(public_key);
729734
goto cleanup;
730735
}
731-
efree(public_key);
736+
zend_string_release(public_key);
732737
}
733738
}
734739
#endif

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)