Skip to content

Commit 6558ae6

Browse files
author
Sascha Schumann
committed
dup fds before fdopen'ing them, so that people cannot deliberately
close stdio streams. This needs to be tested on non-UNIX platforms. PR: php#11599, php#8624
1 parent 5bf89ce commit 6558ae6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/standard/php_fopen_wrapper.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <stdio.h>
2323
#include <stdlib.h>
24+
#include <unistd.h>
2425

2526
#include "php.h"
2627
#include "php_globals.h"
@@ -37,11 +38,11 @@ FILE *php_fopen_url_wrap_php(char *path, char *mode, int options, int *issock, i
3738
*issock = 0;
3839

3940
if (!strcasecmp(res, "stdin")) {
40-
return fdopen(STDIN_FILENO, mode);
41+
return fdopen(dup(STDIN_FILENO), mode);
4142
} else if (!strcasecmp(res, "stdout")) {
42-
return fdopen(STDOUT_FILENO, mode);
43+
return fdopen(dup(STDOUT_FILENO), mode);
4344
} else if (!strcasecmp(res, "stderr")) {
44-
return fdopen(STDERR_FILENO, mode);
45+
return fdopen(dup(STDERR_FILENO), mode);
4546
}
4647

4748
return NULL;

0 commit comments

Comments
 (0)