summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/db/db.c2
-rw-r--r--ext/dba/dba_db2.c2
-rw-r--r--ext/dba/dba_db3.c2
-rw-r--r--ext/session/mod_files.c2
-rw-r--r--ext/session/session.c2
-rw-r--r--ext/standard/filestat.c6
-rw-r--r--ext/standard/link.c2
-rw-r--r--ext/zlib/zlib.c4
-rw-r--r--main/php.h2
-rw-r--r--main/php_virtual_cwd.c43
-rw-r--r--main/php_virtual_cwd.h1
11 files changed, 52 insertions, 16 deletions
diff --git a/ext/db/db.c b/ext/db/db.c
index c2f666d44c..c1df8348c9 100644
--- a/ext/db/db.c
+++ b/ext/db/db.c
@@ -319,7 +319,7 @@ dbm_info *php_dbm_open(char *filename, char *mode) {
strcat(lockfn, ".lck");
#if NFS_HACK
- while((last_try = stat(lockfn,&sb))==0) {
+ while((last_try = V_STAT(lockfn,&sb))==0) {
retries++;
php_sleep(1);
if (retries>30) break;
diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c
index 4543dc8666..de68974358 100644
--- a/ext/dba/dba_db2.c
+++ b/ext/dba/dba_db2.c
@@ -61,7 +61,7 @@ DBA_OPEN_FUNC(db2)
type = info->mode == DBA_READER ? DB_UNKNOWN :
info->mode == DBA_TRUNC ? DB_BTREE :
- stat(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
+ V_STAT(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
gmode = info->mode == DBA_READER ? DB_RDONLY :
info->mode == DBA_CREAT ? DB_CREATE :
diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c
index 50d1a28c35..ae1405705d 100644
--- a/ext/dba/dba_db3.c
+++ b/ext/dba/dba_db3.c
@@ -61,7 +61,7 @@ DBA_OPEN_FUNC(db3)
type = info->mode == DBA_READER ? DB_UNKNOWN :
info->mode == DBA_TRUNC ? DB_BTREE :
- stat(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
+ V_STAT(info->path, &check_stat) ? DB_BTREE : DB_UNKNOWN;
gmode = info->mode == DBA_READER ? DB_RDONLY :
info->mode == DBA_CREAT ? DB_CREATE :
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
index 64879d5969..e9ff89212f 100644
--- a/ext/session/mod_files.c
+++ b/ext/session/mod_files.c
@@ -175,7 +175,7 @@ static int _ps_files_cleanup_dir(const char *dirname, int maxlifetime)
snprintf(buf, MAXPATHLEN, "%s%c%s", dirname, DIR_DELIMITER,
entry->d_name) > 0 &&
/* stat the directory entry */
- stat(buf, &sbuf) == 0 &&
+ V_STAT(buf, &sbuf) == 0 &&
/* is it expired? */
(now - sbuf.st_atime) > maxlifetime) {
unlink(buf);
diff --git a/ext/session/session.c b/ext/session/session.c
index 589759e69c..63a785139f 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -497,7 +497,7 @@ static void last_modified(void)
path = SG(request_info).path_translated;
if (path) {
- if (stat(path, &sb) == -1) {
+ if (V_STAT(path, &sb) == -1) {
return;
}
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index 81f70fdf14..dcb26d2ffc 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -385,7 +385,7 @@ PHP_FUNCTION(touch)
RETURN_FALSE;
/* create the file if it doesn't exist already */
- ret = stat((*filename)->value.str.val, &sb);
+ ret = V_STAT((*filename)->value.str.val, &sb);
if (ret == -1) {
file = V_FOPEN((*filename)->value.str.val, "w");
if (file == NULL) {
@@ -439,7 +439,7 @@ static void php_stat(const char *filename, int type, pval *return_value)
#if HAVE_SYMLINK
BG(lsb).st_mode = 0; /* mark lstat buf invalid */
#endif
- if (stat(BG(CurrentStatFile),&BG(sb))==-1) {
+ if (V_STAT(BG(CurrentStatFile),&BG(sb))==-1) {
if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */
php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno));
}
@@ -457,7 +457,7 @@ static void php_stat(const char *filename, int type, pval *return_value)
/* do lstat if the buffer is empty */
if (!BG(lsb).st_mode) {
- if (lstat(BG(CurrentStatFile),&BG(lsb)) == -1) {
+ if (V_LSTAT(BG(CurrentStatFile),&BG(lsb)) == -1) {
php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno));
RETURN_FALSE;
}
diff --git a/ext/standard/link.c b/ext/standard/link.c
index d955be19a4..ad918ebca7 100644
--- a/ext/standard/link.c
+++ b/ext/standard/link.c
@@ -88,7 +88,7 @@ PHP_FUNCTION(linkinfo)
}
convert_to_string_ex(filename);
- ret = lstat((*filename)->value.str.val, &sb);
+ ret = V_LSTAT((*filename)->value.str.val, &sb);
if (ret == -1) {
php_error(E_WARNING, "LinkInfo failed (%s)", strerror(errno));
RETURN_LONG(-1L);
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index d76952fe4e..6360addd7f 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -206,7 +206,7 @@ static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char
if(PG(doc_root)) {
snprintf(trypath, MAXPATHLEN, "%s%s", PG(doc_root), filename);
} else {
- strncpy(trypath,filename,sizeof(trypath));
+ strlcpy(trypath,filename,sizeof(trypath));
}
if (!php_checkuid(trypath,2)) {
return(NULL);
@@ -251,7 +251,7 @@ static gzFile *php_gzopen_with_path(char *filename, char *mode, char *path, char
}
snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
if (PG(safe_mode)) {
- if (stat(trypath,&sb) == 0 &&(!php_checkuid(trypath,2))) {
+ if (V_STAT(trypath,&sb) == 0 &&(!php_checkuid(trypath,2))) {
efree(pathbuf);
return(NULL);
}
diff --git a/main/php.h b/main/php.h
index db23919e21..97596d16d3 100644
--- a/main/php.h
+++ b/main/php.h
@@ -295,6 +295,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
#define V_CHDIR_FILE(path) virtual_chdir_file(path)
#define V_GETWD(buf)
#define V_STAT(path, buff) virtual_stat(path, buff)
+#define V_LSTAT(path, buff) virtual_lstat(path, buff)
#else
#define V_GETCWD(buff, size) getcwd(buff,size)
#define V_FOPEN(path, mode) fopen(path, mode)
@@ -302,6 +303,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
#define V_CHDIR_FILE(path) chdir_file(path)
#define V_GETWD(buf) getwd(buf)
#define V_STAT(path, buff) stat(path, buff)
+#define V_LSTAT(path, buff) lstat(path, buff)
#endif
#include "zend_constants.h"
diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c
index 3613cc77f8..a3d98baa21 100644
--- a/main/php_virtual_cwd.c
+++ b/main/php_virtual_cwd.c
@@ -7,9 +7,10 @@
#include <stdlib.h>
#include <ctype.h>
-
#include "php_virtual_cwd.h"
+#define VIRTUAL_CWD_DEBUG 0
+
#ifdef ZTS
#include "TSRM.h"
#endif
@@ -148,6 +149,9 @@ CWD_API void virtual_cwd_startup()
CWD_API void virtual_cwd_activate(char *filename)
{
+#if VIRTUAL_CWD_DEBUG
+ fprintf(stderr, "Changing dir to %s\n", filename);
+#endif
if (filename) {
virtual_chdir_file(filename);
}
@@ -238,7 +242,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
old_state = (cwd_state *) malloc(sizeof(cwd_state));
CWD_STATE_COPY(old_state, state);
-
+#if VIRTUAL_CWD_DEBUG
+ fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
+#endif
if (IS_ABSOLUTE_PATH(path_copy, path_length)) {
copy_amount = COPY_WHEN_ABSOLUTE;
is_absolute = 1;
@@ -310,7 +316,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
free(old_state);
efree(free_path);
-
+#if VIRTUAL_CWD_DEBUG
+ fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd);
+#endif
return (ret);
}
@@ -324,6 +332,8 @@ CWD_API int virtual_chdir(char *path)
CWD_API int virtual_chdir_file(char *path)
{
int length = strlen(path);
+ char *temp;
+ int retval;
if (length == 0) {
return 1; /* Can't cd to empty string */
@@ -334,8 +344,16 @@ CWD_API int virtual_chdir_file(char *path)
if (length == -1) {
return virtual_chdir(path);
}
- path[length] = DEFAULT_SLASH;
- return virtual_chdir(path);
+
+ temp = (char *) malloc(length+1);
+ memcpy(temp, path, length);
+ temp[length] = 0;
+#if VIRTUAL_CWD_DEBUG
+ fprintf (stderr, "Changing directory to %s\n", temp);
+#endif
+ retval = virtual_chdir(temp);
+ free(temp);
+ return retval;
}
@@ -382,6 +400,21 @@ CWD_API int virtual_stat(const char *path, struct stat *buf)
return retval;
}
+CWD_API int virtual_lstat(const char *path, struct stat *buf)
+{
+ cwd_state new_state;
+ int retval;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+
+ virtual_file_ex(&new_state, path, NULL);
+
+ retval = lstat(new_state.cwd, buf);
+ CWD_STATE_FREE(&new_state);
+ return retval;
+}
+
#if 0
main(void)
diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h
index a7548c8d59..406ebf1240 100644
--- a/main/php_virtual_cwd.h
+++ b/main/php_virtual_cwd.h
@@ -43,6 +43,7 @@ CWD_API int virtual_chdir_file(char *path);
CWD_API int virtual_filepath(char *path, char **filepath);
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
CWD_API int virtual_stat(const char *path, struct stat *buf);
+CWD_API int virtual_lstat(const char *path, struct stat *buf);
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
ZEND_BEGIN_MODULE_GLOBALS(cwd)