Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Zend/tests/require_directory.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Including a directory generates an error
--FILE--
<?php

/* Just a random test directory */
$dir = __DIR__ . '/variadic';
require $dir;

?>
--EXPECTF--
Notice: require(): Read of %d bytes failed with errno=21 Is a directory in %s on line %d

Fatal error: Uncaught Error: Failed opening required '%s' (include_path='.:') in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion ext/standard/tests/file/bug35740.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include (__DIR__);
echo "Done\n";
?>
--EXPECTF--
Warning: include(%s): Failed to open stream: %s in %s on line %d
Notice: include(): Read of %s bytes failed with errno=21 Is a directory in %s on line %d

Warning: include(): Failed opening '%s' for inclusion (include_path='%s') in %s on line %d
Done
25 changes: 1 addition & 24 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef struct {

static int do_fstat(php_stdio_stream_data *d, int force)
{
if (!d->cached_fstat || (force && !d->no_forced_fstat)) {
if (!d->cached_fstat || force) {
int fd;
int r;

Expand Down Expand Up @@ -1188,30 +1188,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
efree(persistent_id);
}

/* WIN32 always set ISREG flag */
#ifndef PHP_WIN32
/* sanity checks for include/require.
* We check these after opening the stream, so that we save
* on fstat() syscalls */
if (options & STREAM_OPEN_FOR_INCLUDE) {
php_stdio_stream_data *self = (php_stdio_stream_data*)ret->abstract;
int r;

r = do_fstat(self, 0);
if ((r == 0 && !S_ISREG(self->sb.st_mode))) {
if (opened_path) {
zend_string_release_ex(*opened_path, 0);
*opened_path = NULL;
}
php_stream_close(ret);
return NULL;
}

/* Make sure the fstat result is reused when we later try to get the
* file size. */
self->no_forced_fstat = 1;
}

if (options & STREAM_USE_BLOCKING_PIPE) {
php_stdio_stream_data *self = (php_stdio_stream_data*)ret->abstract;
self->is_pipe_blocking = 1;
Expand Down
Loading