Bug #73448 [NEW]: odbc_errormsg returns trash, always 513 bytes

From: Date: Wed, 02 Nov 2016 22:53:41 +0000
Subject: Bug #73448 [NEW]: odbc_errormsg returns trash, always 513 bytes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205161@lists.php.net to get a copy of this message
From:             honza dot hink at gmail dot com
Operating system: Windows 7, 8.1, Server 2012 R2
PHP version:      7.0.12
Package:          ODBC related
Bug Type:         Bug
Bug description:odbc_errormsg returns trash, always 513 bytes

Description:
------------
If odbc_exec returns false then odbc_errormsg returns always 513 bytes
in my examples. The correct error message is at the beginning, then some
null bytes follows and the rest is binary trash.

If next odbc_exec is OK then odbc_errormsg returns similar content as
before, the trash may be different. It doesn't return empty string as
written in documentation.

The example (19 lines) can be used as simple page (like index.php).
It contains 4 SQL commands and displays error text in raw and
hexadecimal form.

Adjust parameters in odbc_connect.

The bug appears in ODBC with MS SQL 2008, 2012, probably all versions,
Apache/2.4.17 (Win32) or IIS 7, FCGI mode, mod_fcgid/2.3.9.
First noticed several months ago, problem probably started with 7.0.0.


Test script:
---------------
<?php
	$con=odbc_connect("MSSQLLocal","sa","your-pwd");
	$sqlCommandList=array("/* empty batch is without error */","/* non
existent procedure xy */ execute xy",
		"/* empty batch, error message is not empty */","/* valid select with
result */ select * from sys.sysobjects");
	foreach($sqlCommandList as $exampleNumber=>$sql){
		$r = @odbc_exec($con,$sql);
		$exampleNumber++;
		if($r)
			{$numfields="Result = $r, field count = ".odbc_num_fields($r);
odbc_free_result($r);}
		else
			{$numfields="Invalid result";}
		$e=odbc_errormsg($con);
		$hex=bin2hex($e);
		print "<hr style=height:5px; color=red><br><div
style=font-width:bold>Example $exampleNumber SQL =  $sql</div>
		<div>$numfields, error text(length=".strlen($e)."): </div>
		<div><pre>$e</pre></div><hr>
		<div style=font-weight:bold>Hexadecimal error content:</div>
		<div style=word-wrap:break-word;max-width:600px>$hex</div>";
	}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=73448&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73448&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73448&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73448&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73448&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73448&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73448&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73448&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73448&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73448&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73448&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73448&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73448&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73448&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73448&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73448&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73448&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73448&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73448&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73448&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73448&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#205161) next »