php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68350 SQL_DESC_OCTET_LENGTH not supported by ADS ODBC driver
Submitted: 2014-11-05 12:48 UTC Modified: 2015-04-28 13:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: frederic dot marchal at wowtechnology dot com Assigned: ab (profile)
Status: Closed Package: ODBC related
PHP Version: 5.4.34 OS:
Private report: No CVE-ID: None
 [2014-11-05 12:48 UTC] frederic dot marchal at wowtechnology dot com
Description:
------------
Running odbc_exec() on an ADS ODBC driver version 11.0 or 11.1 for Linux produces errors such as:

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

The error is produced because libadsodbc.so returns an invalid value when SQLColAttributes is queried with SQL_DESC_OCTET_LENGTH.

It worked before this commit:

https://github.com/php/php-src/commit/7301994c28d548c5a4eda6a3a4ae0fab6af04636

The patch simply checks the return value from SQLColAttributes and falls back on the old method to get the column size.


Patches

ads_odbc_exec.patch (last revision 2014-11-05 12:49 UTC) by frederic dot marchal at wowtechnology dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-11 16:46 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2015-04-11 16:46 UTC] cmb@php.net
I assume the actual reason for the misbehavior is bug #68087, which
has already been fixed in 5.5.19 and 5.6.3, but will not be fixed
for PHP 5.4.

Can you please confirm that?
 [2015-04-11 17:21 UTC] frederic dot marchal at wowtechnology dot com
I assume this is the very last php_odbc.c file:

https://github.com/php/php-src/blob/master/ext/odbc/php_odbc.c

Then, no, the problem isn't fixed. You can see, at line 994, that the return code rc is ignored. The problem I face is that the ODBC driver doesn't support SQL_DESC_OCTET_LENGTH. The ODBC driver rightfully returns an error code when PHP queries that attribute. As PHP doesn't check the return code it continues with the uninitialized displaysize and tries to emalloc a memory block with a size of whatever happen to be in displaysize. You can see the result in my initial report.

You should have a look at the patch I supplied. It has been included in Debian and, so far, it works fine.
 [2015-04-11 17:55 UTC] cmb@php.net
Due to bug #68087 SQL_DESC_OCTET_LENGTH could have been applied for
other fields than SQL_*CHAR, which is likely to fail. The
respective fix[1] resolved this issue. For drivers not recognizing
SQL_DESC_OCTET_LENGTH for SQL_*CHAR fields, of course that wouldn't
help.

I'm unassigning myself, so someone else with access to an ADS and
php-src karma can pick up.

[1] <https://github.com/php/php-src/commit/df9078ea55e2bd60d718c6e6948b70311650fe39>
 [2015-04-11 17:55 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2015-04-12 00:01 UTC] cmb@php.net
-Status: Feedback +Status: Open
 [2015-04-14 20:00 UTC] cmb@php.net
Might be related to bug #69354.
 [2015-04-15 13:37 UTC] frederic dot marchal at wowtechnology dot com
The patch https://github.com/php/php-src/commit/b3a027d6103b69bb935431dbec2e59eb20454862 solves the problem for the ADS ODBC driver too.

Simply replacing SQLColAttributes with SQLColAttribute (without 's') does the trick.

So, this bug is similar to bug #69354 and the solution proposed there is better than my patch as it addresses the cause of the problem instead of working around it.
 [2015-04-17 19:00 UTC] ab@php.net
@frederic, if it's fixed with #69354 as well - so that's great. The subsequent fixes to the ext/odbc in the 5.5 branch could be of some interest for you, as well. 

I think it's hardly going into 5.4 though, as it's more about ODBC 3.0 support and not security. So probably you've two ways - either upgrading to at least 5.5 or patching 5.4 manually. Anyway seems this ticket is done now, please close it by chance.

Thanks.
 [2015-04-19 07:58 UTC] frederic dot marchal at wowtechnology dot com
-Status: Open +Status: Closed
 [2015-04-19 07:58 UTC] frederic dot marchal at wowtechnology dot com
Problem adequately solved by bug #69354.
 [2015-04-28 13:19 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2015-04-28 13:19 UTC] ab@php.net
@frederic FYI i've applied your patch (in master also added a warning)for the sake of compatibility. Seems the driver from the ticket #69381 has a real issue with this.

Thanks.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Oct 21 16:01:26 2018 UTC