Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

static libevent/curl support; adjusting file_exists behavior for php files; bugfixes #439

Closed
wants to merge 5 commits into from

2 participants

@d1saster

I think the commit messages are all self-explaining:
Two commits are real bugfixes (one for the issue #319 and one if you compile without __thread TLS support) and the other two commits just make it easier to deploy a compiled project.

d1saster added some commits
@d1saster d1saster Only ThreadLocalNoCheck has a method named getNoCheck. 52841be
@d1saster d1saster fix for the static versions of libevent and libcurl f3d6c73
@d1saster d1saster fix SEGFAULT in Extension::LoadModules 88cb1e6
@d1saster d1saster 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.
f0b4ff9
@d1saster d1saster fix the hphpi/eval support
The commit which changed 'file_exists' also changed the hphpi/eval
behavior. This patch fixes this in the way that we only pretend that local
.php files do not exist for compiled projects without eval support.
329fbc0
@ptarjan

We're closing out all bugs older than 2 months. http://www.hiphop-php.com/wp/?p=575

If this is still an issue, please re-open it, and in order of goodness:

  1. Give detailed repro steps
  2. Write a test case in hphp/tests/quick (run it with hphp/tests/run) and send the pull request
  3. Fix it in a pull request
@ptarjan ptarjan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 8, 2011
  1. @d1saster
  2. @d1saster
  3. @d1saster
  4. @d1saster

    Handle .php files differently in file_exists

    d1saster authored
    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.
  5. @d1saster

    fix the hphpi/eval support

    d1saster authored
    The commit which changed 'file_exists' also changed the hphpi/eval
    behavior. This patch fixes this in the way that we only pretend that local
    .php files do not exist for compiled projects without eval support.
This page is out of date. Refresh to see the latest.
View
47 CMake/HPHPFindLibs.cmake
@@ -51,11 +51,19 @@ include_directories(${LIBMEMCACHED_INCLUDE_DIR})
find_package(PCRE REQUIRED)
include_directories(${PCRE_INCLUDE_DIRS})
+if (LINUX OR FREEBSD)
+ FIND_LIBRARY (CRYPT_LIB NAMES xcrypt crypt)
+ FIND_LIBRARY (RT_LIB rt)
+elseif (APPLE)
+ FIND_LIBRARY (CRYPT_LIB crypto)
+ FIND_LIBRARY (ICONV_LIB iconv)
+endif()
+
# libevent checks
find_package(LibEvent REQUIRED)
include_directories(${LIBEVENT_INCLUDE_DIR})
-set(CMAKE_REQUIRED_LIBRARIES "${LIBEVENT_LIB}")
+set(CMAKE_REQUIRED_LIBRARIES "${LIBEVENT_LIB}" ${RT_LIB})
CHECK_FUNCTION_EXISTS("evhttp_bind_socket_with_fd" HAVE_CUSTOM_LIBEVENT)
if (NOT HAVE_CUSTOM_LIBEVENT)
unset(HAVE_CUSTOM_LIBEVENT CACHE)
@@ -80,7 +88,20 @@ endif()
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
-set(CMAKE_REQUIRED_LIBRARIES "${CURL_LIBRARIES}")
+# LDAP
+find_package(Ldap REQUIRED)
+include_directories(${LDAP_INCLUDE_DIR})
+
+# OpenSSL libs
+find_package(OpenSSL REQUIRED)
+include_directories(${OPENSSL_INCLUDE_DIR})
+
+# ZLIB
+find_package(ZLIB REQUIRED)
+include_directories(${ZLIB_INCLUDE_DIR})
+
+set(CMAKE_REQUIRED_LIBRARIES "${CURL_LIBRARIES}" ${LDAP_LIBRARIES} ${OPENSSL_LIBRARIES}
+ ${ZLIB_LIBRARIES} ${RT_LIB})
CHECK_FUNCTION_EXISTS("curl_multi_select" HAVE_CUSTOM_CURL)
if (NOT HAVE_CUSTOM_CURL)
unset(HAVE_CUSTOM_CURL CACHE)
@@ -216,14 +237,6 @@ link_directories(${TBB_LIBRARY_DIRS})
find_package(Mcrypt REQUIRED)
include_directories(${Mcrypt_INCLUDE_DIR})
-# OpenSSL libs
-find_package(OpenSSL REQUIRED)
-include_directories(${OPENSSL_INCLUDE_DIR})
-
-# ZLIB
-find_package(ZLIB REQUIRED)
-include_directories(${ZLIB_INCLUDE_DIR})
-
find_package(BZip2 REQUIRED)
include_directories(${BZIP2_INCLUDE_DIR})
add_definitions(${BZIP2_DEFINITIONS})
@@ -232,10 +245,6 @@ add_definitions(${BZIP2_DEFINITIONS})
find_package(ONIGURUMA REQUIRED)
include_directories(${ONIGURUMA_INCLUDE_DIRS})
-# LDAP
-find_package(Ldap REQUIRED)
-include_directories(${LDAP_INCLUDE_DIR})
-
# ncurses, readline and history
#set(CURSES_NEED_NCURSES true)
find_package(Ncurses REQUIRED)
@@ -270,14 +279,6 @@ if (NOT CCLIENT_HAS_SSL)
add_definitions(-DSKIP_IMAP_SSL=1)
endif()
-if (LINUX OR FREEBSD)
- FIND_LIBRARY (CRYPT_LIB NAMES xcrypt crypt)
- FIND_LIBRARY (RT_LIB rt)
-elseif (APPLE)
- FIND_LIBRARY (CRYPT_LIB crypto)
- FIND_LIBRARY (ICONV_LIB iconv)
-endif()
-
if (LINUX)
FIND_LIBRARY (CAP_LIB cap)
@@ -336,7 +337,7 @@ macro(hphp_link target)
target_link_libraries(${target} ${PCRE_LIBRARY})
target_link_libraries(${target} ${ICU_LIBRARIES} ${ICU_I18N_LIBRARIES})
target_link_libraries(${target} ${LIBEVENT_LIB})
- target_link_libraries(${target} ${CURL_LIBRARIES})
+ target_link_libraries(${target} ${CURL_LIBRARIES})
if (LINUX)
target_link_libraries(${target} ${CAP_LIB})
View
28 src/compiler/analysis/analysis_result.cpp
@@ -3059,13 +3059,28 @@ void AnalysisResult::outputCPPHashTableInvokeFile(
" }\n"
" return NULL;\n"
"}\n"
- "\n";
+ "\n"
+ "bool included_php_file(CStrRef file) {\n";
const char text3[] =
+ " if (findFile(file.c_str(), file->hash()) != NULL) return true;\n"
+ " struct stat s;\n"
+ " // With eval support we have to consider every .php file as included.\n"
+ " String translated = File::TranslatePath(file);\n"
+ " return stat(translated.data(), &s) == 0 && !S_ISDIR(s.st_mode);\n"
+ "}\n"
+ "\n";
+
+ const char text4[] =
+ " return findFile(file.c_str(), file->hash()) != NULL;\n"
+ "}\n"
+ "\n";
+
+ const char text5[] =
"pm_t ptr = findFile(s.c_str(), s->hash());\n"
"if (ptr) return ptr(once, variables, get_globals());\n";
- const char text4[] =
+ const char text6[] =
" return throw_missing_file(s.c_str());\n"
"}\n";
@@ -3084,12 +3099,17 @@ void AnalysisResult::outputCPPHashTableInvokeFile(
}
}
cg_printf(text2, tableSize - 1, tableSize - 1);
+ if (needEvalHook) {
+ cg_printf(text3);
+ } else {
+ cg_printf(text4);
+ }
outputCPPInvokeFileHeader(cg);
- cg_printf(text3);
+ cg_printf(text5);
if (needEvalHook) outputCPPEvalHook(cg);
if (entries.size() == 1) outputCPPDefaultInvokeFile(cg, entries[0]);
cg_indentEnd();
- cg_printf(text4);
+ cg_printf(text6);
}
void AnalysisResult::outputCPPDynamicClassTables(
View
2  src/compiler/analysis/variable_table.cpp
@@ -1111,7 +1111,7 @@ void VariableTable::outputCPPGlobalVariablesImpl(CodeGenerator &cg,
"}\n"
"\n"
"#else /* USE_GCC_FAST_TLS */\n"
- "static ThreadLocal<GlobalVariables *> g_variables;\n"
+ "static ThreadLocalNoCache<GlobalVariables *> g_variables;\n"
"GlobalVariables *get_global_variables() {\n"
" GlobalVariables *g = *(g_variables.getNoCheck());\n"
" ASSERT(g);\n"
View
4 src/hphp/externals.cpp
@@ -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 */) {
View
1  src/runtime/base/externals.h
@@ -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);
View
35 src/runtime/ext/ext_file.cpp
@@ -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;
View
4 src/runtime/ext/extension.cpp
@@ -50,6 +50,10 @@ Extension::Extension(litstr name, const char *version /* = "" */)
}
void Extension::LoadModules(Hdf hdf) {
+ if (s_registered_extensions == NULL) {
+ s_registered_extensions = new ExtensionMap();
+ }
+
ASSERT(s_registered_extensions);
for (ExtensionMap::const_iterator iter = s_registered_extensions->begin();
iter != s_registered_extensions->end(); ++iter) {
View
3  src/test/test_externals.cpp
@@ -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 */) {
View
7 src/third_party/libafdt/CMakeLists.txt
@@ -41,15 +41,16 @@ CHECK_FUNCTION_EXISTS("socket" HAVE_SOCKET)
CHECK_FUNCTION_EXISTS("strerror" HAVE_STRERROR)
find_package(LibEvent)
+FIND_LIBRARY (RT_LIB rt)
IF(LibEvent_FOUND)
set(CMAKE_REQUIRED_INCLUDES "${LIBEVENT_INCLUDE_DIR}")
- set(CMAKE_REQUIRED_LIBRARIES "${LIBEVENT_LIB}")
+ set(CMAKE_REQUIRED_LIBRARIES "${LIBEVENT_LIB}" ${RT_LIB})
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CheckLibeventVersion.c VERSION_CHECK_SOURCE)
CHECK_SYMBOL_EXISTS("event_get_version_number" "event.h" HAVE_EVENT_GET_VERSION_NUMBER)
- IF(HAVE_EVENT_GET_VERSION_NUMBER)
+ IF(HAVE_EVENT_GET_VERSION_NUMBER)
SET(CMAKE_REQUIRED_DEFINITIONS
-DHAVE_EVENT_GET_VERSION_NUMBER
-DEVENT_VERSION_WANTED=0x2000900)
@@ -63,9 +64,11 @@ IF(LibEvent_FOUND)
-DEVENT_VERSION_WANTED=0x1040500)
CHECK_C_SOURCE_COMPILES("${VERSION_CHECK_SOURCE}" HAVE_LIBEVENT_145)
IF(NOT HAVE_LIBEVENT_145)
+ unset(HAVE_LIBEVENT_145 CACHE)
SET(CMAKE_REQUIRED_DEFINITIONS -DEVENT_VERSION_WANTED=0x1040300)
CHECK_C_SOURCE_COMPILES("${VERSION_CHECK_SOURCE}" HAVE_LIBEVENT_143)
IF(NOT LIBEVENT_VERSION_143)
+ unset(HAVE_LIBEVENT_143 CACHE)
message(FATAL_ERROR "Couldn't find at least libevent 1.4.3+")
ENDIF()
ELSE()
Something went wrong with that request. Please try again.