When getcwd() fails in certain places, we end up passing a
zero length cwd_state to virtual_file_ex(). This causes
virtual_file_ex() to assume the path to be "/", thus:
include("foo.php");
ends up trying to open, "/foo.php", which is wrong. If you
want to play with this problem, its very easy to simulate
on a non-broken environment, just do:
#define VCWD_GETCWD(buff, size) (EACCES)
(or to a func that returns EACCES in case &VCWD_GETCWD() is
ever used).
-James
On Sat, 15 Feb 2003, Andi Gutmans wrote:
> Hey,
>
> The fchdir() part of the patch looks fine but I didn't quite understand the
> rest. PHP only uses realpath() if it doesn't fail, so what is the exact
> problem? What does that other code do?
>
> Andi
>
> At 03:29 PM 2/12/2003 -0500, James E. Flemer wrote:
> >Well all the fancy new streams code in 4.3.0 seems to
> >tickle a Solaris issue with getcwd(). It seems that under
> >certain cases solaris' getcwd() fails when other os' work.
> >Consequently 4.3.0 causes a huge ammount of breakage for
> >some sites running solaris. Below is a patch that seems to
> >work around the problem. This may not be the best
> >approach, but it was an attempt at a quick-fix so that
> >4.3.0 would be usable for now. This problem has bug
> >number: #21310 [1]. Comments welcome. I'd like to commit
> >this (or similar) before any more releases are made.
> >
> >-James <[EMAIL PROTECTED]>
> >
> >[1] http://bugs.php.net/21310
> >
> >]] Patch sponsored by: The University of Vermont [[
> >Index: TSRM/tsrm_virtual_cwd.c
> >===================================================================
> >RCS file: /repository/TSRM/tsrm_virtual_cwd.c,v
> >retrieving revision 1.41
> >diff -u -b -u -r1.41 tsrm_virtual_cwd.c
> >--- TSRM/tsrm_virtual_cwd.c 6 Nov 2002 18:07:22 -0000 1.41
> >+++ TSRM/tsrm_virtual_cwd.c 12 Feb 2003 04:39:11 -0000
> >@@ -303,7 +303,7 @@
> > return (0);
> >
> > #if !defined(TSRM_WIN32) && !defined(NETWARE)
> >- if (IS_ABSOLUTE_PATH(path, path_length)) {
> >+ if (IS_ABSOLUTE_PATH(path, path_length) || (state->cwd_length < 1))
> >{
> > if (use_realpath && realpath(path, resolved_path)) {
> > path = resolved_path;
> > path_length = strlen(path);
> >@@ -363,6 +363,7 @@
> > }
> >
> >
> >+ if (state->cwd_length > 0 || IS_ABSOLUTE_PATH(path, path_length)) {
> > ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
> > while (ptr) {
> > ptr_length = strlen(ptr);
> >@@ -416,6 +417,11 @@
> > state->cwd[state->cwd_length+1] = '\0';
> > state->cwd_length++;
> > }
> >+ } else {
> >+ state->cwd = (char *) realloc(state->cwd, path_length+1);
> >+ memcpy(state->cwd, path, path_length+1);
> >+ state->cwd_length = path_length;
> >+ }
> >
> > if (verify_path && verify_path(state)) {
> > CWD_STATE_FREE(state);
> >Index: main/main.c
> >===================================================================
> >RCS file: /repository/php4/main/main.c,v
> >retrieving revision 1.512.2.5
> >diff -u -b -u -r1.512.2.5 main.c
> >--- main/main.c 16 Dec 2002 15:44:06 -0000 1.512.2.5
> >+++ main/main.c 12 Feb 2003 04:39:12 -0000
> >@@ -1507,7 +1507,11 @@
> > {
> > zend_file_handle *prepend_file_p, *append_file_p;
> > zend_file_handle prepend_file, append_file;
> >+#ifdef VIRTUAL_DIR
> > char *old_cwd;
> >+#else
> >+ int old_cwd_fd;
> >+#endif
> > char *old_primary_file_path = NULL;
> > int retval = 0;
> >
> >@@ -1515,9 +1519,11 @@
> > if (php_handle_special_queries(TSRMLS_C)) {
> > return 0;
> > }
> >+#ifdef VIRTUAL_DIR
> > #define OLD_CWD_SIZE 4096
> > old_cwd = do_alloca(OLD_CWD_SIZE);
> > old_cwd[0] = '\0';
> >+#endif
> >
> > zend_try {
> > #ifdef PHP_WIN32
> >@@ -1528,7 +1534,11 @@
> >
> > if (primary_file->type == ZEND_HANDLE_FILENAME
> > && primary_file->filename) {
> >+#ifdef VIRTUAL_DIR
> > VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
> >+#else
> >+ old_cwd_fd = open(".", 0);
> >+#endif
> > VCWD_CHDIR_FILE(primary_file->filename);
> > }
> >
> >@@ -1578,10 +1588,14 @@
> >
> > } zend_end_try();
> >
> >+#ifdef VIRTUAL_DIR
> > if (old_cwd[0] != '\0') {
> > VCWD_CHDIR(old_cwd);
> > }
> > free_alloca(old_cwd);
> >+#else
> >+ fchdir(old_cwd_fd);
> >+#endif
> > return retval;
> > }
> > /* }}} */
> >Index: main/safe_mode.c
> >===================================================================
> >RCS file: /repository/php4/main/safe_mode.c,v
> >retrieving revision 1.51
> >diff -u -b -u -r1.51 safe_mode.c
> >--- main/safe_mode.c 6 Nov 2002 18:07:23 -0000 1.51
> >+++ main/safe_mode.c 12 Feb 2003 04:39:12 -0000
> >@@ -121,6 +121,8 @@
> > VCWD_REALPATH(filename, path);
> > *s = DEFAULT_SLASH;
> > } else {
> >+ path[0] = '.';
> >+ path[1] = '\0';
> > VCWD_GETCWD(path, sizeof(path));
> > }
> > } /* end CHECKUID_ALLOW_ONLY_DIR */
> >
> >
> >--
> >PHP Development Mailing List <http://www.php.net/>
> >To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php