Bug #69354 [NEW]: Incorrect use of SQLColAttributes with ODBC 3.0
| From: | php at mdjnet dot dk | Date: | Thu, 02 Apr 2015 08:35:30 +0000 |
| Subject: | Bug #69354 [NEW]: Incorrect use of SQLColAttributes with ODBC 3.0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191781@lists.php.net to get a copy of this message | ||
From: php at mdjnet dot dk
Operating system: All
PHP version: 5.6.7
Package: ODBC related
Bug Type: Bug
Bug description:Incorrect use of SQLColAttributes with ODBC 3.0
Description:
------------
Since php was changed to odbc 3.0 (#68964), an old hidden bug has
surfaced. This bug is related to both #68350 "SQL_DESC_OCTET_LENGTH not
supported by ADS ODBC driver" and #68014 "Result data values can be
truncated because of incorrect column display sizes".
In odbc 3.0, SQLColAttributes is deprecated, instead SQLColAttribute
should be used, which in turn supports SQL_DESC_OCTET_LENGTH, introduced
with odbc 3.0.
The bug is in ext/odbc/php_odbc.c, the function odbc_bindcols, in the
middle of the big switch. With ODBCVER set to 0x0300 as of php 5.6.7,
the extra cases of SQL_WCHAR and SQL_WVARCHAR come into effect, setting
colfieldid to SQL_DESC_OCTET_LENGTH also for SQL_CHAR and SQL_VARCHAR
due to a rather suspiscious fall-through strategy, that worked well for
ODBCVER < 0x0300. However, not all odbc drivers allow for
SQLColAttributes to be called with SQL_DESC_OCTET_LENGTH.
If SQLColAttributes fails, the effect is that strings lifted from
subsequent calls to odbc_result become truncated, probably because of
uninitialized variables, as the code doesn't even look at the return
value of SQLColAttributes (same effect as in #68014, which appears to be
fixed judging from looking at the code).
The correct fix would be to call SQLColAttribute instead of
SQLColAttributes, if ODBCVER >= 0x0300, and to actually check the return
value before using the result of the call (displaysize).
I have never figured out how to build my own php, so I have not tried to
fix it directly in php_odbc.c, but I have tried to fix my odbc driver to
support SQL_DESC_OCTET_LENGTH in SQLColAttributes, and that does indeed
fix the problem.
--
Edit bug report at https://bugs.php.net/bug.php?id=69354&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69354&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69354&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69354&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69354&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69354&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69354&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69354&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69354&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69354&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69354&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69354&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69354&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69354&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69354&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69354&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69354&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69354&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69354&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69354&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69354&r=mysqlcfg