scottmac                Mon Nov 17 19:34:03 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/sqlite3        sqlite3.c 
  Log:
  MFH Fix #46033 - Segfault when instantiating SQLite3stmt and SQLite3Result 
directly.
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/sqlite3/sqlite3.c?r1=1.1.2.15&r2=1.1.2.16&diff_format=u
Index: php-src/ext/sqlite3/sqlite3.c
diff -u php-src/ext/sqlite3/sqlite3.c:1.1.2.15 
php-src/ext/sqlite3/sqlite3.c:1.1.2.16
--- php-src/ext/sqlite3/sqlite3.c:1.1.2.15      Mon Nov 17 11:27:59 2008
+++ php-src/ext/sqlite3/sqlite3.c       Mon Nov 17 19:34:03 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: sqlite3.c,v 1.1.2.15 2008/11/17 11:27:59 felipe Exp $ */
+/* $Id: sqlite3.c,v 1.1.2.16 2008/11/17 19:34:03 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -512,7 +512,7 @@
 }
 /* }}} */
 
-/* {{{ proto SQLite3Result SQLite3::querySingle(String Query [, entire_row = 
false])
+/* {{{ proto SQLite3Result SQLite3::querySingle(String Query [, bool 
entire_row = false])
    Returns a string of the first column, or an array of the entire row. */
 PHP_METHOD(sqlite3, querySingle)
 {
@@ -1063,6 +1063,8 @@
                return;
        }
 
+       SQLITE3_CHECK_INITIALIZED(stmt_obj->initialised, SQLite3)
+
        if (stmt_obj->bound_params) {
                zend_hash_internal_pointer_reset(stmt_obj->bound_params);
                while (zend_hash_get_current_data(stmt_obj->bound_params, (void 
**)&param) == SUCCESS) {
@@ -1167,6 +1169,47 @@
 }
 /* }}} */
 
+/* {{{ proto int SQLite3Stmt::__construct(SQLite3 dbobject, String Statement)
+   __constructor for SQLite3Stmt. */
+PHP_METHOD(sqlite3stmt, __construct)
+{
+       php_sqlite3_stmt *stmt_obj;
+       php_sqlite3_db_object *db_obj;
+       zval *object = getThis();
+       zval *db_zval;
+       stmt_obj = (php_sqlite3_stmt *)zend_object_store_get_object(object 
TSRMLS_CC);
+       char *sql;
+       int sql_len, errcode;
+
+       zend_replace_error_handling(EH_THROW, NULL, NULL TSRMLS_CC);
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &db_zval, 
php_sqlite3_sc_entry, &sql, &sql_len) == FAILURE) {
+               return;
+       }
+
+       db_obj = (php_sqlite3_db_object *)zend_object_store_get_object(db_zval 
TSRMLS_CC);
+
+       SQLITE3_CHECK_INITIALIZED(db_obj->initialised, SQLite3)
+
+       if (!sql_len) {
+               RETURN_FALSE;
+       }
+
+       stmt_obj->db_obj = db_obj;
+       stmt_obj->db_obj_zval = db_zval;
+
+       Z_ADDREF_P(db_zval);
+       
+       errcode = sqlite3_prepare_v2(db_obj->db, sql, sql_len, 
&(stmt_obj->stmt), NULL);
+       if (errcode != SQLITE_OK) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to prepare 
statement: %d, %s", errcode, sqlite3_errmsg(db_obj->db));
+               zval_dtor(return_value);
+               RETURN_FALSE;
+       }
+       stmt_obj->initialised = 1;
+}
+/* }}} */
+
 /* {{{ proto int SQLite3Result::numColumns()
    Number of columns in the result set. */
 PHP_METHOD(sqlite3result, numColumns)
@@ -1327,6 +1370,21 @@
 }
 /* }}} */
 
+/* {{{ proto int SQLite3Result::__construct()
+   __constructor for SQLite3Result. */
+PHP_METHOD(sqlite3result, __construct)
+{
+       php_sqlite3_result *result_obj;
+       zval *object = getThis();
+       result_obj = (php_sqlite3_result *)zend_object_store_get_object(object 
TSRMLS_CC);
+
+       zend_replace_error_handling(EH_THROW, NULL, NULL TSRMLS_CC);
+
+       php_error_docref(NULL TSRMLS_CC, E_WARNING, "SQLite3Result cannot be 
directly instantiated");
+
+}
+/* }}} */
+
 /* {{{ arginfo */
 ZEND_BEGIN_ARG_INFO(arginfo_sqlite3_open, 0)
        ZEND_ARG_INFO(0, filename)
@@ -1417,6 +1475,10 @@
        ZEND_ARG_INFO(0, type)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO(arginfo_sqlite3stmt_construct, 1)
+       ZEND_ARG_INFO(0, sqlite3)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_numcolumns, 0)
 ZEND_END_ARG_INFO()
 
@@ -1437,6 +1499,9 @@
 
 ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_finalize, 0)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_sqlite3result_construct, 0)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 /* {{{ php_sqlite3_class_methods */
@@ -1457,7 +1522,7 @@
        PHP_ME(sqlite3,         createFunction,         
arginfo_sqlite3_createfunction, ZEND_ACC_PUBLIC)
        PHP_ME(sqlite3,         createAggregate,        
arginfo_sqlite3_createaggregate, ZEND_ACC_PUBLIC)
        /* Aliases */
-       PHP_MALIAS(sqlite3,     __construct, open, arginfo_sqlite3_open, 
ZEND_ACC_PUBLIC)
+       PHP_MALIAS(sqlite3,     __construct, open, arginfo_sqlite3_open, 
ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        {NULL, NULL, NULL}
 };
 /* }}} */
@@ -1471,6 +1536,7 @@
        PHP_ME(sqlite3stmt, execute,    arginfo_sqlite3stmt_execute, 
ZEND_ACC_PUBLIC)
        PHP_ME(sqlite3stmt, bindParam,  arginfo_sqlite3stmt_bindparam, 
ZEND_ACC_PUBLIC)
        PHP_ME(sqlite3stmt, bindValue,  arginfo_sqlite3stmt_bindvalue, 
ZEND_ACC_PUBLIC)
+       PHP_ME(sqlite3stmt, __construct, arginfo_sqlite3stmt_construct, 
ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        {NULL, NULL, NULL}
 };
 /* }}} */
@@ -1482,7 +1548,8 @@
        PHP_ME(sqlite3result, columnType,               
arginfo_sqlite3result_columntype, ZEND_ACC_PUBLIC)
        PHP_ME(sqlite3result, fetchArray,               
arginfo_sqlite3result_fetcharray, ZEND_ACC_PUBLIC)
        PHP_ME(sqlite3result, reset,                    
arginfo_sqlite3result_reset, ZEND_ACC_PUBLIC)
-       PHP_ME(sqlite3result, finalize,         arginfo_sqlite3result_finalize, 
ZEND_ACC_PUBLIC)
+       PHP_ME(sqlite3result, finalize,                 
arginfo_sqlite3result_finalize, ZEND_ACC_PUBLIC)
+       PHP_ME(sqlite3result, __construct,              
arginfo_sqlite3result_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        {NULL, NULL, NULL}
 };
 /* }}} */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to