summaryrefslogtreecommitdiff
path: root/ext/pdo
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo')
-rw-r--r--ext/pdo/pdo.c2
-rw-r--r--ext/pdo/pdo_dbh.c10
-rw-r--r--ext/pdo/pdo_sql_parser.c25
-rw-r--r--ext/pdo/pdo_sql_parser.re23
-rw-r--r--ext/pdo/pdo_sqlstate.c2
-rw-r--r--ext/pdo/pdo_stmt.c2
-rw-r--r--ext/pdo/php_pdo.h2
-rw-r--r--ext/pdo/php_pdo_driver.h2
-rw-r--r--ext/pdo/php_pdo_int.h2
-rw-r--r--ext/pdo/tests/bug65946.phpt32
10 files changed, 70 insertions, 32 deletions
diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c
index 452c27b591..f3c9b65766 100644
--- a/ext/pdo/pdo.c
+++ b/ext/pdo/pdo.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index d5860b1a1e..4f5a391704 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -196,7 +196,7 @@ static char *dsn_from_uri(char *uri, char *buf, size_t buflen TSRMLS_DC) /* {{{
}
/* }}} */
-/* {{{ proto void PDO::__construct(string dsn, string username, string passwd [, array options])
+/* {{{ proto void PDO::__construct(string dsn[, string username[, string passwd [, array options]]])
*/
static PHP_METHOD(PDO, dbh_constructor)
{
@@ -460,7 +460,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
if (dbstmt_ce->constructor) {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval *retval;
+ zval *retval = NULL;
fci.size = sizeof(zend_fcall_info);
fci.function_table = &dbstmt_ce->function_table;
@@ -495,7 +495,7 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
zval_dtor(object);
ZVAL_NULL(object);
object = NULL; /* marks failure */
- } else {
+ } else if (retval) {
zval_ptr_dtor(&retval);
}
@@ -1226,7 +1226,7 @@ static PHP_METHOD(PDO, getAvailableDrivers)
/* }}} */
/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo___construct, 0, 0, 3)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo___construct, 0, 0, 1)
ZEND_ARG_INFO(0, dsn)
ZEND_ARG_INFO(0, username)
ZEND_ARG_INFO(0, passwd)
diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c
index aea362fdb2..341e664bbe 100644
--- a/ext/pdo/pdo_sql_parser.c
+++ b/ext/pdo/pdo_sql_parser.c
@@ -4,7 +4,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -586,7 +586,9 @@ safe:
}
plc->freeq = 1;
} else {
- switch (Z_TYPE_P(param->parameter)) {
+ zval tmp_param = *param->parameter;
+ zval_copy_ctor(&tmp_param);
+ switch (Z_TYPE(tmp_param)) {
case IS_NULL:
plc->quoted = "NULL";
plc->qlen = sizeof("NULL")-1;
@@ -594,20 +596,20 @@ safe:
break;
case IS_BOOL:
- convert_to_long(param->parameter);
-
+ convert_to_long(&tmp_param);
+ /* fall through */
case IS_LONG:
case IS_DOUBLE:
- convert_to_string(param->parameter);
- plc->qlen = Z_STRLEN_P(param->parameter);
- plc->quoted = Z_STRVAL_P(param->parameter);
- plc->freeq = 0;
+ convert_to_string(&tmp_param);
+ plc->qlen = Z_STRLEN(tmp_param);
+ plc->quoted = estrdup(Z_STRVAL(tmp_param));
+ plc->freeq = 1;
break;
default:
- convert_to_string(param->parameter);
- if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
- Z_STRLEN_P(param->parameter), &plc->quoted, &plc->qlen,
+ convert_to_string(&tmp_param);
+ if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL(tmp_param),
+ Z_STRLEN(tmp_param), &plc->quoted, &plc->qlen,
param->param_type TSRMLS_CC)) {
/* bork */
ret = -1;
@@ -616,6 +618,7 @@ safe:
}
plc->freeq = 1;
}
+ zval_dtor(&tmp_param);
}
} else {
plc->quoted = Z_STRVAL_P(param->parameter);
diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re
index 1936a37340..fa8ef187fa 100644
--- a/ext/pdo/pdo_sql_parser.re
+++ b/ext/pdo/pdo_sql_parser.re
@@ -228,7 +228,9 @@ safe:
}
plc->freeq = 1;
} else {
- switch (Z_TYPE_P(param->parameter)) {
+ zval tmp_param = *param->parameter;
+ zval_copy_ctor(&tmp_param);
+ switch (Z_TYPE(tmp_param)) {
case IS_NULL:
plc->quoted = "NULL";
plc->qlen = sizeof("NULL")-1;
@@ -236,20 +238,20 @@ safe:
break;
case IS_BOOL:
- convert_to_long(param->parameter);
-
+ convert_to_long(&tmp_param);
+ /* fall through */
case IS_LONG:
case IS_DOUBLE:
- convert_to_string(param->parameter);
- plc->qlen = Z_STRLEN_P(param->parameter);
- plc->quoted = Z_STRVAL_P(param->parameter);
- plc->freeq = 0;
+ convert_to_string(&tmp_param);
+ plc->qlen = Z_STRLEN(tmp_param);
+ plc->quoted = estrdup(Z_STRVAL(tmp_param));
+ plc->freeq = 1;
break;
default:
- convert_to_string(param->parameter);
- if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL_P(param->parameter),
- Z_STRLEN_P(param->parameter), &plc->quoted, &plc->qlen,
+ convert_to_string(&tmp_param);
+ if (!stmt->dbh->methods->quoter(stmt->dbh, Z_STRVAL(tmp_param),
+ Z_STRLEN(tmp_param), &plc->quoted, &plc->qlen,
param->param_type TSRMLS_CC)) {
/* bork */
ret = -1;
@@ -258,6 +260,7 @@ safe:
}
plc->freeq = 1;
}
+ zval_dtor(&tmp_param);
}
} else {
plc->quoted = Z_STRVAL_P(param->parameter);
diff --git a/ext/pdo/pdo_sqlstate.c b/ext/pdo/pdo_sqlstate.c
index 7c92c1c0f3..533a35c404 100644
--- a/ext/pdo/pdo_sqlstate.c
+++ b/ext/pdo/pdo_sqlstate.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 04e71823b9..2735aede41 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/php_pdo.h b/ext/pdo/php_pdo.h
index f8a8ce377e..0b8bf6dfa9 100644
--- a/ext/pdo/php_pdo.h
+++ b/ext/pdo/php_pdo.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h
index ede2d6fb76..56a69cac30 100644
--- a/ext/pdo/php_pdo_driver.h
+++ b/ext/pdo/php_pdo_driver.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/php_pdo_int.h b/ext/pdo/php_pdo_int.h
index 91d0bf0412..2740fc8e63 100644
--- a/ext/pdo/php_pdo_int.h
+++ b/ext/pdo/php_pdo_int.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/ext/pdo/tests/bug65946.phpt b/ext/pdo/tests/bug65946.phpt
new file mode 100644
index 0000000000..1c4bd8d6c4
--- /dev/null
+++ b/ext/pdo/tests/bug65946.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Bug #65946 (pdo_sql_parser.c permanently converts values bound to strings)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+$db->exec('CREATE TABLE test(id int)');
+$db->exec('INSERT INTO test VALUES(1)');
+$stmt = $db->prepare('SELECT * FROM test LIMIT :limit');
+$stmt->bindValue('limit', 1, PDO::PARAM_INT);
+if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
+if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
+var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(1) {
+ ["id"]=>
+ string(1) "1"
+ }
+}