#48419 [Fbk->Opn]: non-portable CGI code (Empty POST data)

2009-06-03 Thread juro at shaw dot ca
 ID:   48419
 User updated by:  juro at shaw dot ca
 Reported By:  juro at shaw dot ca
-Status:   Feedback
+Status:   Open
 Bug Type: CGI related
 Operating System: Windows XP
 PHP Version:  5.2.10RC1
 New Comment:

Using Windows XP OS we use a generic HTTP server (not Apache, not IIS,
etc.) with CGI/1.1 support (no FCGI). 
PHP script fills a form and uses:

CONTENT_TYPE = application/x-www-form-urlencoded 
REQUEST_METHOD = POST

to post some filled form data. The HTTP server launches PHP-CGI.EX and
writes the posted data to a handle that was redirected to be
PHP-CGI.EXE STDIN. PHP-CGI.EXE does receive the data, which can be
viewed correctly using the code:

print "$HTTP_RAW_POST_DATA";
print_r($_SERVER["HTTP_RAW_POST_DATA"]);

Both printouts show correctly (urlencoded) posted data.
However, the $_POST array is empty:

if (empty($_POST)) 
{
echo "POST empty !!! (No data was submitted)";
}


Previous Comments:


[2009-05-31 13:57:24] j...@php.net

Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.




--------

[2009-05-28 20:36:32] juro at shaw dot ca

Description:

Using a generic web server with a simple CGI support (running on
Windows XP), I fail to obtain any $_POST data. However, raw post data
are OK. Raw post data is sent to the PHP-CGI.exe via redirected pipe
handle. PHP-CGI reads correctly posted raw data using stdin.

I suspect the culprit may be with the following PHP source code:

File:cgi_main.c
Routine:static int sapi_cgi_read_post(char *buffer, uint count_bytes
TSRMLS_DC)

...
tmp_read_bytes = read(0, buffer + read_bytes, count_bytes -
read_bytes);
...

Low level i/o functions read,write,open are not 100% portable.
The code is most like meant to read stdin. Assuming that file
descriptor for stdin is numerically equal to 0 on all platforms is
wrong. 

The code should be probably something like this
tmp_read_bytes = read(_fileno(stdin), buffer + read_bytes, count_bytes
- read_bytes);









-- 
Edit this bug report at http://bugs.php.net/?id=48419&edit=1



#48419 [NEW]: non-portable CGI code (Empty POST data)

2009-05-28 Thread juro at shaw dot ca
From: juro at shaw dot ca
Operating system: Windows XP
PHP version:  5.2.10RC1
PHP Bug Type: CGI related
Bug description:  non-portable CGI code (Empty POST data)

Description:

Using a generic web server with a simple CGI support (running on Windows
XP), I fail to obtain any $_POST data. However, raw post data are OK. Raw
post data is sent to the PHP-CGI.exe via redirected pipe handle. PHP-CGI
reads correctly posted raw data using stdin.

I suspect the culprit may be with the following PHP source code:

File:cgi_main.c
Routine:static int sapi_cgi_read_post(char *buffer, uint count_bytes
TSRMLS_DC)

...
tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes);
...

Low level i/o functions read,write,open are not 100% portable.
The code is most like meant to read stdin. Assuming that file descriptor
for stdin is numerically equal to 0 on all platforms is wrong. 

The code should be probably something like this
tmp_read_bytes = read(_fileno(stdin), buffer + read_bytes, count_bytes -
read_bytes);





-- 
Edit bug report at http://bugs.php.net/?id=48419&edit=1
-- 
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48419&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48419&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48419&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48419&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48419&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48419&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=48419&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=48419&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=48419&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=48419&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=48419&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=48419&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=48419&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48419&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=48419&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=48419&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=48419&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=48419&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=48419&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=48419&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=48419&r=mysqlcfg