]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #39656 (crash when calling fetch() on a PDO statment object
authorIlia Alshanetsky <iliaa@php.net>
Tue, 28 Nov 2006 16:28:07 +0000 (16:28 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 28 Nov 2006 16:28:07 +0000 (16:28 +0000)
after closeCursor()).

ext/pdo/pdo_stmt.c
ext/pdo_pgsql/pgsql_statement.c

index bf4ae99781227b5e73875e4a7ad9d282033f31d9..cc9eea7be06d84b2814d0299ba862e88c92e045e 100755 (executable)
@@ -434,7 +434,7 @@ static PHP_METHOD(PDOStatement, execute)
                if (!stmt->executed) {
                        /* this is the first execute */
 
-                       if (stmt->dbh->alloc_own_columns) {
+                       if (stmt->dbh->alloc_own_columns && !stmt->columns) {
                                /* for "big boy" drivers, we need to allocate memory to fetch
                                 * the results into, so lets do that now */
                                ret = pdo_stmt_describe_columns(stmt TSRMLS_CC);
@@ -565,6 +565,10 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno TSRMLS_DC
 static int do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori,
        long offset, int do_bind TSRMLS_DC) /* {{{ */
 {
+       if (!stmt->executed) {
+               return 0;
+       }
+
        if (!dispatch_param_event(stmt, PDO_PARAM_EVT_FETCH_PRE TSRMLS_CC)) {
                return 0;
        }
@@ -1888,6 +1892,7 @@ static PHP_METHOD(PDOStatement, closeCursor)
                        }
                                
                } while (1);
+               stmt->executed = 0;
                RETURN_TRUE;
        }
 
@@ -1897,7 +1902,7 @@ static PHP_METHOD(PDOStatement, closeCursor)
                PDO_HANDLE_STMT_ERR();
                RETURN_FALSE;
        }
-
+       stmt->executed = 0;
        RETURN_TRUE;
 }
 /* }}} */
index 291c3e28462d559778c667915815ea48e709f124..d6b0bb2fe2cd014922e26b737e762e356d0e3c2d 100644 (file)
@@ -140,7 +140,7 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
                return 0;
        }
 
-       if(!stmt->executed) {
+       if (!stmt->executed && !stmt->column_count) {
                stmt->column_count = (int) PQnfields(S->result);
                S->cols = ecalloc(stmt->column_count, sizeof(pdo_pgsql_column));
        }