ID: 30962 Updated by: [EMAIL PROTECTED] Reported By: richard dot quadling at bandvulc dot co dot uk -Status: Open +Status: Closed Bug Type: MSSQL related Operating System: Windows XP Pro SP2 PHP Version: 5.0.2 New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2004-12-02 14:36:14] richard dot quadling at bandvulc dot co dot uk Description: ------------ This bug has been reported before but repeatedly closed as a bogus bug. It is NOT bogus. It is NOT a problem in the library. It IS a bug in the PHP code. The problem is for any column where the content is NULL, the value retrieved by PHP is ' '. That is a single space. The bug is in php_mssql.c (/* $Id: php_mssql.c,v 1.137.2.4 2004/11/15 23:35:50 iliaa Exp $ */) Lines 798 to 810 are currently ... case SQLTEXT: { int length; char *data = charcol(offset); length=dbdatlen(mssql_ptr->link,offset); #if ilia_0 while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */ length--; } #endif ZVAL_STRINGL(result, data, length, 1); break; } The problem is that "length" is never tested to see if it is zero, as per the Microsoft documentation (Online books and look for dbdata). It says ... dbdata ... returns a BYTE pointer to the data for the column. A NULL BYTE pointer is returned if there is no such column or if the data has a null value. To make sure that the data is really a null value, check for a return of 0 from dbdatlen. and ... Remarks. The data is not null-terminated. To get the length of the data, use dbdatlen. I would propose that the php_mssql.c code would be as follows ... case SQLTEXT: { int length; char *data = charcol(offset); length=dbdatlen(mssql_ptr->link,offset); if (length == 0) { ZVAL_EMPTY_STRING(result); // Force the return of an empty string if the length is 0 as data MAY not be NULL. } else { #if ilia_0 while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */ length--; } #endif ZVAL_STRINGL(result, data, length, 1); } break; } Unfortunately, I am not in a position to test this (well, I have MSVC++V6.0 Standard, but cannot get PHP to compile. I am not very familiar with MSVC++ and its setup to know what is missing). If someone can explain how I can submit this to the actual source online for compilation, then I'd be very grateful. I'd be even more grateful if someone could help me get PHP compiled. Even money may be sent, though I'd rather buy beer or something fizzy for the ladies. This possible fix does not interfere with the removing of trailing spaces, though I wonder what would happen if Regards, Richard Quadling. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=30962&edit=1