(<5.3) Segfault when calling an undefined method on PDOStatement
Until PHP 5.3, calling an undefined method on a PDOStatement
object causes a segfault:
php -n -r 'dl("pdo.so"); $stmt = new PDOStatement(); $stmt->someMethodWhichDoesNotExist();' Segmentation fault
The actual line of code is in php/ext/pdo/pdo_stmt.c, line 2788:
static union _zend_function *dbstmt_method_get( #if PHP_API_VERSION >= 20041225 zval **object_pp, #else zval *object, #endif char *method_name, int method_len TSRMLS_DC) { zend_function *fbc = NULL; char *lc_method_name; #if PHP_API_VERSION >= 20041225 zval *object = *object_pp; #endif lc_method_name = emalloc(method_len + 1); zend_str_tolower_copy(lc_method_name, method_name, method_len); if (zend_hash_find(&Z_OBJCE_P(object)->function_table, lc_method_name, method_len+1, (void**)&fbc) == FAILURE) { pdo_stmt_t *stmt = (pdo_stmt_t*)zend_object_store_get_object(object TSRMLS_CC); /* not a pre-defined method, nor a user-defined method; check * the driver specific methods */ /// v HERE v /// if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { if (!pdo_hash_methods(stmt->dbh, PDO_DBH_DRIVER_METHOD_KIND_STMT TSRMLS_CC) || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { /// ^ HERE ^ /// goto out; } } if (zend_hash_find(stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT], lc_method_name, method_len+1, (void**)&fbc) == FAILURE) { fbc = NULL; goto out; } /* got it */ } out: efree(lc_method_name); return fbc; }