Skip to content

Remove include "sanity check" to get better error #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Zend/tests/require_directory.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--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: require(): Failed opening required '%s' (include_path='%s') in %s on line %d
2 changes: 2 additions & 0 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
zend_string *compiled_filename;

if (zend_stream_fixup(file_handle, &buf, &size) == FAILURE) {
/* Still add it to open_files so the file_handle destruction logic works correctly. */
zend_llist_add_element(&CG(open_files), file_handle);
Comment on lines +520 to +521
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this was already merged as part of other change ( 2f64844 ) so it should be removed from this PR.

return FAILURE;
}

Expand Down
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
26 changes: 1 addition & 25 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ typedef struct {
unsigned is_pipe:1; /* don't try and seek */
unsigned cached_fstat:1; /* sb is valid */
unsigned is_pipe_blocking:1; /* allow blocking read() on pipes, currently Windows only */
unsigned no_forced_fstat:1; /* Use fstat cache even if forced */
unsigned _reserved:28;

int lock_flag; /* stores the lock state */
Expand All @@ -153,7 +152,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 @@ -1084,30 +1083,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