php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48419 non-portable STDIN fileno in cgi_main.c
Submitted: 2009-05-28 20:36 UTC Modified: 2009-06-04 13:58 UTC
From: juro at shaw dot ca Assigned: pajoye (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 5.2.10RC1 OS: win32 only - Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: juro at shaw dot ca
New email:
PHP Version: OS:

 

 [2009-05-28 20:36 UTC] 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);





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-31 13:57 UTC] jani@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-06-03 14:19 UTC] juro at shaw dot ca
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)";
}
 [2009-06-04 11:54 UTC] jani@php.net
I changed it to be more portable under *nix. Pierre can check the win32 
part of it.
 [2009-06-04 13:58 UTC] pajoye@php.net
Those are defined as well on Windows. 

For the record: after a short research, it seems safe to use 0/1( or 2 for err) when these constants are not defined.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 11:02:27 2025 UTC