Permalink
Browse files

Handle .php files differently in file_exists

Consider the following code

	if (file_exists('blub.php'))
		require_once ('blub.php');

which can fail because of 2 reasons:
1. blub.php is compiled with all the other files, but is no longer
   present at runtime.
2. blub.php is not compiled, but does exist in the filesystem.

The patch fixes the first case where file_exists now returns true
and adds a workaround for the second case where we now pretend that
the file does not exist.
  • Loading branch information...
d1saster committed Dec 8, 2011
1 parent 7d99d6c commit 5f7d320c59cdede3df9993c1d76f171920633873
@@ -3059,6 +3059,10 @@ void AnalysisResult::outputCPPHashTableInvokeFile(
" }\n"
" return NULL;\n"
"}\n"
"\n"
"bool included_php_file(CStrRef s) {\n"
" return findFile(s.c_str(), s->hash()) != NULL;\n"
"}\n"
"\n";
const char text3[] =
View
@@ -52,6 +52,10 @@ void init_static_variables() {}
void free_global_variables() {}
Array get_global_state() { return Array(); }
bool included_php_file(CStrRef s) {
return false;
}
Variant invoke_file(CStrRef path, bool once /* = false */,
LVariableTable* variables /* = NULL */,
const char *currDir /* = NULL */) {
@@ -127,6 +127,7 @@ extern ObjectData *create_builtin_object_only_no_init(CStrRef s,
* Dynamically include a file.
*/
class LVariableTable;
extern bool included_php_file(CStrRef s);
extern Variant invoke_file(CStrRef file, bool once = false,
LVariableTable* variables = NULL,
const char *currentDir = NULL);
@@ -760,7 +760,42 @@ bool f_is_uploaded_file(CStrRef filename) {
return false;
}
static bool is_file_included(CStrRef file, void* ctx) {
// mimic the include_impl_invoke behavior
if (file[0] == '/') {
if (RuntimeOption::SandboxMode || !RuntimeOption::AlwaysUseRelativePath) {
if (included_php_file(file)) {
return true;
}
}
string server_root = RuntimeOption::SourceRoot;
if (server_root.empty()) {
server_root = string(g_context->getCwd()->data());
if (server_root.empty() || server_root[server_root.size() - 1] != '/') {
server_root += "/";
}
}
String rel_path(Util::relativePath(server_root, string(file.data())));
return included_php_file(rel_path);
} else {
return included_php_file(file);
}
}
bool f_file_exists(CStrRef filename) {
// check whether it's an included php file
if (!resolve_include(filename, "",
&is_file_included, NULL).isNull()) {
return true;
}
// ignore all other php files
if (filename.find(".php") == filename.size() - 4) {
Logger::Verbose("%s/%d: All .php files that are not built-in are ommited: %s",
__FUNCTION__, __LINE__, filename.data());
return false;
}
if (filename.empty() ||
(access(File::TranslatePath(filename, true).data(), F_OK)) < 0) {
return false;
@@ -321,6 +321,9 @@ void init_global_variables() {
void free_global_variables() { g_variables.destroy();}
void init_literal_varstrings() {}
bool has_eval_support = true;
bool included_php_file(CStrRef s) {
return false;
}
Variant invoke_file(CStrRef path, bool once /* = false */,
LVariableTable* variables /* = NULL */,
const char *currentDir /* = NULL */) {

0 comments on commit 5f7d320

Please sign in to comment.