]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #39215 (Inappropriate close of stdin/stdout/stderr).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 3 Nov 2006 13:34:39 +0000 (13:34 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 3 Nov 2006 13:34:39 +0000 (13:34 +0000)
ext/standard/php_fopen_wrapper.c

index e6b9c502e6075117026a15089d8a9a933603cf0e..a5bf5a130e3bb44895c7df476962a31cdd5822bc 100644 (file)
@@ -191,11 +191,41 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
        }  
        
        if (!strcasecmp(path, "stdin")) {
-               fd = !strcmp(sapi_module.name, "cli") ? STDIN_FILENO : dup(STDIN_FILENO);
+               if (!strcmp(sapi_module.name, "cli")) {
+                       static int cli_in = 0;
+                       fd = STDIN_FILENO;
+                       if (cli_in) {
+                               fd = dup(fd);
+                       } else {
+                               cli_in = 1;
+                       }
+               } else {
+                       fd = dup(STDIN_FILENO);
+               }
        } else if (!strcasecmp(path, "stdout")) {
-               fd = !strcmp(sapi_module.name, "cli") ? STDOUT_FILENO : dup(STDOUT_FILENO);
+               if (!strcmp(sapi_module.name, "cli")) {
+                       static int cli_out = 0;
+                       fd = STDOUT_FILENO;
+                       if (cli_out++) {
+                               fd = dup(fd);
+                       } else {
+                               cli_out = 1;
+                       }
+               } else {
+                       fd = dup(STDOUT_FILENO);
+               }
        } else if (!strcasecmp(path, "stderr")) {
-               fd = !strcmp(sapi_module.name, "cli") ? STDERR_FILENO : dup(STDERR_FILENO);
+               if (!strcmp(sapi_module.name, "cli")) {
+                       static int cli_err = 0;
+                       fd = STDERR_FILENO;
+                       if (cli_err++) {
+                               fd = dup(fd);
+                       } else {
+                               cli_err = 1;
+                       }
+               } else {
+                       fd = dup(STDERR_FILENO);
+               }
        } else if (!strncasecmp(path, "filter/", 7)) {
                /* Save time/memory when chain isn't specified */
                if (strchr(mode, 'r') || strchr(mode, '+')) {