]> granicus.if.org Git - php/commitdiff
MFH Fix bug #48679 - Crash in SQLite with count on an unbuffered query set
authorScott MacVicar <scottmac@php.net>
Thu, 25 Jun 2009 00:07:20 +0000 (00:07 +0000)
committerScott MacVicar <scottmac@php.net>
Thu, 25 Jun 2009 00:07:20 +0000 (00:07 +0000)
ext/sqlite/sqlite.c
ext/sqlite/tests/bug48679.phpt [new file with mode: 0644]

index 78b9857fc3d79b97de2bdee8dfa780c8e12207e4..296b68437ae0b260e0f1b75e1728e72acd9b0040 100644 (file)
@@ -2481,6 +2481,11 @@ static int sqlite_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
 {
        sqlite_object *obj = (sqlite_object*) zend_object_store_get_object(object TSRMLS_CC);
 
+       if (obj->u.res == NULL) {
+               zend_throw_exception(sqlite_ce_exception, "Row count is not available for this query", 0 TSRMLS_CC);
+               return FAILURE;
+       }
+
        if (obj->u.res->buffered) {
                * count = obj->u.res->nrows;
                return SUCCESS;
diff --git a/ext/sqlite/tests/bug48679.phpt b/ext/sqlite/tests/bug48679.phpt
new file mode 100644 (file)
index 0000000..4b0c3f4
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #48679 (sqlite2 count on unbuffered query causes segfault)
+--SKIPIF--
+<?php 
+if (!extension_loaded("sqlite")) print "skip"; 
+?>
+--FILE--
+<?php
+
+try {
+       $x = new sqliteunbuffered;
+       count($x);
+} catch (SQLiteException $e) {
+       var_dump($e->getMessage());
+}
+echo "Done\n";
+?>
+--EXPECT--     
+string(41) "Row count is not available for this query"
+Done