[PATCH] PDO invalid bindParam causes segfault

From: Date: Tue, 08 Nov 2005 02:44:54 +0000
Subject: [PATCH] PDO invalid bindParam causes segfault
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3201@lists.php.net to get a copy of this message
Here is a little fix to prevent a segfault. This will happen when ever you try to bind a invalid parameter, and then try to execute (see attached php script) Curt --

Index: ext/pdo/pdo_stmt.c =================================================================== RCS file: /repository/php-src/ext/pdo/pdo_stmt.c,v retrieving revision 1.118.2.15 diff -u -r1.118.2.15 pdo_stmt.c --- ext/pdo/pdo_stmt.c 31 Oct 2005 07:47:40 -0000 1.118.2.15 +++ ext/pdo/pdo_stmt.c 5 Nov 2005 17:10:32 -0000 @@ -322,7 +322,11 @@ /* tell the driver we just created a parameter */ if (stmt->methods->param_hook) { - return stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC TSRMLS_CC); + if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC TSRMLS_CC) ) { + /* The driver said there is no such parameter */ + zend_hash_del(hash, pparam->name, pparam->namelen); + return 0; + } } return 1; <?php try { $dbh = new PDO('mysql:host=localhost;dbname=test', '', ''); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->exec('create table foo ( bar char(3) NULL )'); $sql = "select bar from foo where bar = ':p'"; $stmt = $dbh->prepare($sql); $p = 'foo'; $stmt->bindParam(':p', $p) or print_r($stmt->errorInfo()); $stmt->execute(); $stmt = null; } catch (PDOException $e) { echo $e, "\n"; } if($dbh) $dbh->exec('drop table IF EXISTS foo');
« previous php.pecl.dev (#3201) next »