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

index 91b37f5c283e8bb02f26f499ca0159d999bd897f..01c52eda49329d6a5b2a9c8322125f5ae64f2f40 100644 (file)
@@ -3021,6 +3021,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..1961179
--- /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--     
+unicode(41) "Row count is not available for this query"
+Done