From f76b9649cd224297e60b17c2de71a78b1966dc3e Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Mon, 28 Oct 2002 00:28:11 +0000 Subject: [PATCH] Fixed bug #20110. --- main/streams.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main/streams.c b/main/streams.c index cbbdba1124..a49c7633f4 100755 --- a/main/streams.c +++ b/main/streams.c @@ -1644,13 +1644,20 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha { FILE *fp; char *realpath = NULL; + struct stat st; + php_stream *ret; realpath = expand_filepath(filename, NULL TSRMLS_CC); fp = fopen(realpath, mode); if (fp) { - php_stream *ret = php_stream_fopen_from_file_rel(fp, mode); + /* this is done to prevent opening of anything other then regular files */ + if (fstat(fileno(fp), &st) == -1 || !S_ISREG(st.st_mode)) { + goto err; + } + + ret = php_stream_fopen_from_file_rel(fp, mode); if (ret) { if (opened_path) { @@ -1662,7 +1669,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, cha return ret; } - + err: fclose(fp); } efree(realpath); -- 2.50.1