You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Jesse Pelton <js...@pkc.com> on 1998/02/18 20:03:28 UTC

os-windows/1834: Cannot write to stdout with WriteFile() in CGI-bin executables

>Number:         1834
>Category:       os-windows
>Synopsis:       Cannot write to stdout with WriteFile() in CGI-bin executables
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Wed Feb 18 11:10:00 PST 1998
>Last-Modified:
>Originator:     jsp@pkc.com
>Organization:
apache
>Release:        1.3b3
>Environment:
Win NT 4.0 SP3
MSVC 5.0
>Description:
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), ...) fails in CGI-bin executables.
GetLastError() returns ERROR_INVALID_HANDLE.  Replacing the call to WriteFile()
with an equivalent fwrite() works.

My guess is that the dup() and dup2() functions used in spawn_child_err_core()
are not completely compatible with the Win32 SDK functions, though
Microsoft claims, "All run-time library routines included with [MSVC] are
compatible with the Win32 API."
>How-To-Repeat:
In a working C/C++ CGI-bin program, replace calls to fwrite(), fputs(), etc,
with calls to WriteFile().
>Fix:
I haven't tested this, but my guess is that using the Win32 APIs (CreatePipe(),
GetStdHandle(), SetStdHandle(), DuplicateHandle(), CloseHandle()) in
spawn_child_err_core() would fix the problem.  (See the MSDN article titled
"Creating a Child Process with Redirected Input and Output" for sample code.)
The obvious question is, would this enable WriteFile(), only to disable
fwrite()%3
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <ap...@Apache.Org> in the Cc line ]
[and leave the subject line UNCHANGED.  This is not done]
[automatically because of the potential for mail loops. ]