Package: php5-odbc
Version: 5.4.34-0+deb7u1
Severity: important
Tags: upstream patch

Dear Maintainer,

After upgrading to php 5.4.34, a script running a query on a Sybase ADS
server using the libadsodbc driver from Sybase fails with errors like
this:

PHP Fatal error:  Out of memory (allocated 524288) (tried to allocate
12415340535808218625 bytes) in SybaseClass.php on line 127

The error occurs on a line running odbc_exec().

It is produced because, now, php queries the returned column length
using the SQL_DESC_OCTET_LENGTH attribute which is not supported by the
underlying ODBC driver. As php doesn't check the return code, it tries
to use the uninitialized size to allocate the memory.

I already reported this bug upstream with a patch:

https://bugs.php.net/bug.php?id=68350



-- System Information:
Debian Release: 7.7
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16-0.bpo.2-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_BE.UTF-8, LC_CTYPE=fr_BE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages php5-odbc depends on:
ii  dpkg                                   1.16.15
ii  libapache2-mod-php5 [phpapi-20100525]  5.4.34-0+deb7u1
ii  libc6                                  2.13-38+deb7u6
ii  libodbc1                               2.2.14p2-5
ii  php5-cgi [phpapi-20100525]             5.4.34-0+deb7u1
ii  php5-cli [phpapi-20100525]             5.4.34-0+deb7u1
ii  php5-common                            5.4.34-0+deb7u1
ii  ucf                                    3.0025+nmu3
ii  unixodbc                               2.2.14p2-5

php5-odbc recommends no packages.

php5-odbc suggests no packages.

-- no debconf information
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index 6729163..23b22d5 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -993,6 +993,15 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC)
 			default:
 				rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), colfieldid,
 								NULL, 0, NULL, &displaysize);
+				if (colfieldid == SQL_DESC_OCTET_LENGTH && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
+					/* Fallback to old method because ADS ODBC driver version 11 doesn't support
+					 * SQL_DESC_OCTET_LENGTH.
+					 */
+					charextraalloc = 1;
+					rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
+									NULL, 0, NULL, &displaysize);
+				}
+
 				/* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */
 				if (result->values[i].coltype == SQL_TIMESTAMP) {
 					displaysize += 3;

Reply via email to