PDO_FIREBIRD patch to improve firebird_handle_get_attribute
[email protected] (Paul Reeves) Tue, 16 Nov 2010 16:42:22 +0100
| Newsgroups | php.pdo |
|---|---|
| Organization | IBPhoenix |
| Message-ID | <[email protected]> |
--Boundary-00=_eZq4MvXtahz5Kwq
Content-Type: Text/Plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
There is a bug and a few omissions in firebird_handle_get_attribute.
Most significantly it declares tmp[200] which is used to store the server
version. Unfortunately, a typical server version string is now over 300 bytes
long. So this call just blows the driver out of the water, leaves this error
in the apache log:
*** stack smashing detected ***: /usr/sbin/httpd2-prefork terminated
[Tue Nov 16 13:42:53 2010] [notice] child pid 11656 exit signal Segmentation
fault (11)
and the user is staring at a server timeout error in the browser. This is
easily fixed by declaring tmp[] to be larger.
Less seriously, these attributes are not handled:
PDO_ATTR_PREFETCH,
PDO_ATTR_TIMEOUT,
PDO_ATTR_FETCH_TABLE_NAMES
so if they are called outside a try..catch then the call will fail badly. It
is not obvious that a try..catch should be required so it is probably better
to just hand these cases in the driver.
I've attached a patch which fixes all of these issues.
Paul
--
Paul Reeves
http://www.ibphoenix.com
Specialists in Firebird support
--Boundary-00=_eZq4MvXtahz5Kwq
Content-Type: text/x-patch;
charset="UTF-8";
name="php-5.3.3-pdo_firebird_driver_attributes.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="php-5.3.3-pdo_firebird_driver_attributes.patch"
--- ext/pdo_firebird/firebird_driver.c.orig 2010-01-12 13:46:54.000000000 +0100
+++ ext/pdo_firebird/firebird_driver.c 2010-11-16 16:23:57.100873646 +0100
@@ -34,6 +34,7 @@
#include "pdo/php_pdo_driver.h"
#include "php_pdo_firebird.h"
#include "php_pdo_firebird_int.h"
+#include "../pdo/php_pdo_driver.h"
static int firebird_alloc_prepare_stmt(pdo_dbh_t*, const char*, long, XSQLDA*, isc_stmt_handle*,
HashTable* TSRMLS_DC);
@@ -547,7 +548,7 @@
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
switch (attr) {
- char tmp[200];
+ char tmp[512];
case PDO_ATTR_AUTOCOMMIT:
ZVAL_LONG(val,dbh->auto_commit);
@@ -590,6 +592,16 @@
ZVAL_STRING(val,tmp,1);
return 1;
}
+
+ case PDO_ATTR_PREFETCH:
+ case PDO_ATTR_TIMEOUT:
+ ZVAL_STRING(val,"This attribute is not relevant for this driver",1);
+ return 1;
+
+ case PDO_ATTR_FETCH_TABLE_NAMES:
+ ZVAL_BOOL(val, H->fetch_table_names );
+ return 1;
+
}
return 0;
}
--Boundary-00=_eZq4MvXtahz5Kwq--