From:             richard dot quadling at bandvulc dot co dot uk
Operating system: Windows XP Pro SP2
PHP version:      5.0.2
PHP Bug Type:     MSSQL related
Bug description:  Space being returned for NULL columns

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 bug report at http://bugs.php.net/?id=30962&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30962&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=30962&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=30962&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30962&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30962&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30962&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30962&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30962&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30962&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30962&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=30962&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=30962&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30962&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30962&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30962&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30962&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30962&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30962&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30962&r=mysqlcfg

Reply via email to