summaryrefslogtreecommitdiff
path: root/main/fopen_wrappers.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/fopen_wrappers.c')
-rw-r--r--main/fopen_wrappers.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c
index 91a1685cf..3d65c85d7 100644
--- a/main/fopen_wrappers.c
+++ b/main/fopen_wrappers.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fopen_wrappers.c,v 1.175.2.3.2.13.2.19 2009/06/18 06:38:30 rasmus Exp $ */
+/* $Id: fopen_wrappers.c 289428 2009-10-09 17:03:56Z pajoye $ */
/* {{{ includes
*/
@@ -93,7 +93,7 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
p = (char **) (base + (size_t) mh_arg1);
- if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN) {
+ if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE) {
/* We're in a PHP_INI_SYSTEM context, no restrictions */
*p = new_value;
return SUCCESS;
@@ -382,9 +382,12 @@ static FILE *php_fopen_and_set_opened_path(const char *path, const char *mode, c
*/
PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC)
{
+ FILE *fp;
+#ifndef PHP_WIN32
+ struct stat st;
+#endif
char *path_info, *filename;
int length;
- zend_bool orig_display_errors;
filename = SG(request_info).path_translated;
path_info = SG(request_info).request_uri;
@@ -451,7 +454,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC)
}
} /* if doc_root && path_info */
- if(filename) {
+ if (filename) {
filename = zend_resolve_path(filename, strlen(filename) TSRMLS_CC);
}
@@ -463,20 +466,32 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC)
STR_FREE(SG(request_info).path_translated);
SG(request_info).path_translated = NULL;
return FAILURE;
- } else {
- STR_FREE(SG(request_info).path_translated);
- SG(request_info).path_translated = filename;
}
+ fp = VCWD_FOPEN(filename, "rb");
+
+#ifndef PHP_WIN32
+ /* refuse to open anything that is not a regular file */
+ if (fp && (0 > fstat(fileno(fp), &st) || !S_ISREG(st.st_mode))) {
+ fclose(fp);
+ fp = NULL;
+ }
+#endif
- orig_display_errors = PG(display_errors);
- PG(display_errors) = 0;
- if (zend_stream_open(filename, file_handle TSRMLS_CC) == FAILURE) {
- PG(display_errors) = orig_display_errors;
+ if (!fp) {
STR_FREE(SG(request_info).path_translated); /* for same reason as above */
SG(request_info).path_translated = NULL;
return FAILURE;
}
- PG(display_errors) = orig_display_errors;
+
+ file_handle->opened_path = expand_filepath(filename, NULL TSRMLS_CC);
+
+ STR_FREE(SG(request_info).path_translated); /* for same reason as above */
+ SG(request_info).path_translated = filename;
+
+ file_handle->filename = SG(request_info).path_translated;
+ file_handle->free_filename = 0;
+ file_handle->handle.fp = fp;
+ file_handle->type = ZEND_HANDLE_FP;
return SUCCESS;
}