From: Ilia Alshanetsky Date: Mon, 28 Oct 2002 00:28:11 +0000 (+0000) Subject: Fixed bug #20110. X-Git-Tag: php-4.3.0RC1~502 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f76b9649cd224297e60b17c2de71a78b1966dc3e;p=php Fixed bug #20110. --- 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);