From: Ilia Alshanetsky Date: Tue, 28 Nov 2006 16:28:07 +0000 (+0000) Subject: MFB: Fixed bug #39656 (crash when calling fetch() on a PDO statment object X-Git-Tag: RELEASE_1_0_0RC1~896 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b703207d5c249851bf7760794ba45257dcdec62;p=php MFB: Fixed bug #39656 (crash when calling fetch() on a PDO statment object after closeCursor()). --- diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index bf4ae99781..cc9eea7be0 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -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; } /* }}} */ diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 291c3e2846..d6b0bb2fe2 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -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)); }