]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #44327 (PDORow::queryString property & numeric offsets / Crash)
authorFelipe Pena <felipe@php.net>
Mon, 3 Nov 2008 15:41:35 +0000 (15:41 +0000)
committerFelipe Pena <felipe@php.net>
Mon, 3 Nov 2008 15:41:35 +0000 (15:41 +0000)
NEWS
ext/pdo/pdo_stmt.c
ext/pdo_mysql/tests/bug44327.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f30ff3e65607be277b2221b92d0626f994a5004f..6b98fb6099add68fe1e63aa25ebb10b22f5abed9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,8 @@ PHP                                                                        NEWS
   different). (Derick)
 - Fixed bug #44938 (gettext functions crash with overly long domain).
   (Christian Schneider, Ilia)
+- Fixed bug #44327 (PDORow::queryString property & numeric offsets / Crash).
+  (Felipe)
 - Fixed bug #43452 (strings containing a weekday, or a number plus weekday
   behaved incorrect of the current day-of-week was the same as the one in the
   phrase).(Derick)
index 145e318084368f4f4c50a85983076776c3fbe26b..431da1ab94b262dbc6929b13194ff64a7bb75e16 100755 (executable)
@@ -2595,6 +2595,9 @@ static zval *row_prop_or_dim_read(zval *object, zval *member, int type TSRMLS_DC
        pdo_stmt_t * stmt = (pdo_stmt_t *) zend_object_store_get_object(object TSRMLS_CC);
        int colno = -1;
 
+       if (Z_TYPE_P(member) == IS_STRING && strcmp(Z_STRVAL_P(member), "queryString") == 0) {
+               return std_object_handlers.read_property(object, member, IS_STRING TSRMLS_CC);
+       }
        MAKE_STD_ZVAL(return_value);
                
        if (Z_TYPE_P(member) == IS_LONG) {
diff --git a/ext/pdo_mysql/tests/bug44327.phpt b/ext/pdo_mysql/tests/bug44327.phpt
new file mode 100644 (file)
index 0000000..3d461c0
--- /dev/null
@@ -0,0 +1,64 @@
+--TEST--
+Bug #44327 (PDORow::queryString property & numeric offsets / Crash)
+--SKIPIF--
+<?php
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+MySQLPDOTest::skip();
+?>
+--FILE--
+<?php
+       require dirname(__FILE__) . '/config.inc';
+       require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+       $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+
+       $stmt = $db->prepare("SELECT 1 AS \"one\""); 
+       $stmt->execute(); 
+       $row = $stmt->fetch(PDO::FETCH_LAZY); 
+       var_dump($row);
+       var_dump($row->{0});
+       var_dump($row->one); 
+       var_dump($row->queryString);
+
+       print "----------------------------------\n";
+
+       @$db->exec("DROP TABLE test");
+       $db->exec("CREATE TABLE test (id INT)");
+       $db->exec("INSERT INTO test(id) VALUES (1)");
+       $stmt = $db->prepare("SELECT id FROM test");
+       $stmt->execute();
+       $row = $stmt->fetch(PDO::FETCH_LAZY);
+       var_dump($row);
+       var_dump($row->queryString);
+       @$db->exec("DROP TABLE test");
+
+       print "----------------------------------\n";
+
+       $stmt = $db->prepare('foo'); 
+       @$stmt->execute();
+       $row = $stmt->fetch();
+       var_dump($row->queryString);
+       
+?>
+--EXPECTF--
+object(PDORow)#%d (2) {
+  ["queryString"]=>
+  string(17) "SELECT 1 AS "one""
+  ["one"]=>
+  string(1) "1"
+}
+string(1) "1"
+string(1) "1"
+string(17) "SELECT 1 AS "one""
+----------------------------------
+object(PDORow)#%d (2) {
+  ["queryString"]=>
+  string(19) "SELECT id FROM test"
+  ["id"]=>
+  string(1) "1"
+}
+string(19) "SELECT id FROM test"
+----------------------------------
+
+Notice: Trying to get property of non-object in %s on line %d
+NULL