wez Mon Mar 17 08:50:24 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4 acinclude.m4 configure.in
/TSRM tsrm_virtual_cwd.c
/php4/main main.c safe_mode.c
Log:
MFH Fix for Bug #21310
Index: php4/acinclude.m4
diff -u php4/acinclude.m4:1.218.2.10 php4/acinclude.m4:1.218.2.11
--- php4/acinclude.m4:1.218.2.10 Tue Mar 11 21:26:58 2003
+++ php4/acinclude.m4 Mon Mar 17 08:50:20 2003
@@ -1,4 +1,4 @@
-dnl $Id: acinclude.m4,v 1.218.2.10 2003/03/12 02:26:58 sniper Exp $
+dnl $Id: acinclude.m4,v 1.218.2.11 2003/03/17 13:50:20 wez Exp $
dnl
dnl This file contains local autoconf functions.
@@ -1446,6 +1446,20 @@
if test "$ac_cv_ebcdic" = "yes"; then
AC_DEFINE(CHARSET_EBCDIC,1, [Define if system uses EBCDIC])
fi
+])
+
+dnl Some systems, notably Solaris, cause getcwd() or realpath to fail if a
+dnl component of the path has execute but not read permissions
+AC_DEFUN([PHP_BROKEN_GETCWD],[
+ AC_MSG_CHECKING([for broken getcwd])
+ os=`uname -sr 2>/dev/null`
+ case $os in
+ SunOS*)
+ AC_DEFINE(HAVE_BROKEN_GETCWD,1, [Define if system has broken getcwd])
+ AC_MSG_RESULT([yes]);;
+ *)
+ AC_MSG_RESULT([no]);;
+ esac
])
AC_DEFUN([PHP_BROKEN_GLIBC_FOPEN_APPEND],[
Index: php4/configure.in
diff -u php4/configure.in:1.396.2.40 php4/configure.in:1.396.2.41
--- php4/configure.in:1.396.2.40 Wed Mar 12 17:21:25 2003
+++ php4/configure.in Mon Mar 17 08:50:21 2003
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.396.2.40 2003/03/12 22:21:25 sniper Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.396.2.41 2003/03/17 13:50:21 wez Exp $ -*- sh -*-
dnl ## Process this file with autoconf to produce a configure script.
divert(1)
@@ -378,6 +378,7 @@
])
PHP_FOPENCOOKIE
+PHP_BROKEN_GETCWD
PHP_BROKEN_GLIBC_FOPEN_APPEND
dnl Checks for typedefs, structures, and compiler characteristics.
Index: TSRM/tsrm_virtual_cwd.c
diff -u TSRM/tsrm_virtual_cwd.c:1.41.2.1 TSRM/tsrm_virtual_cwd.c:1.41.2.2
--- TSRM/tsrm_virtual_cwd.c:1.41.2.1 Tue Dec 31 11:23:06 2002
+++ TSRM/tsrm_virtual_cwd.c Mon Mar 17 08:50:21 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: tsrm_virtual_cwd.c,v 1.41.2.1 2002/12/31 16:23:06 sebastian Exp $ */
+/* $Id: tsrm_virtual_cwd.c,v 1.41.2.2 2003/03/17 13:50:21 wez Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -303,7 +303,10 @@
return (0);
#if !defined(TSRM_WIN32) && !defined(NETWARE)
- if (IS_ABSOLUTE_PATH(path, path_length)) {
+ /* cwd_length can be 0 when getcwd() fails.
+ * This can happen under solaris when a dir does not have read permissions
+ * but *does* have execute permissions */
+ 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,58 +366,64 @@
}
- ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
- while (ptr) {
- ptr_length = strlen(ptr);
+ 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);
- if (IS_DIRECTORY_UP(ptr, ptr_length)) {
- char save;
+ if (IS_DIRECTORY_UP(ptr, ptr_length)) {
+ char save;
- save = DEFAULT_SLASH;
+ save = DEFAULT_SLASH;
#define PREVIOUS state->cwd[state->cwd_length - 1]
- while (IS_ABSOLUTE_PATH(state->cwd, state->cwd_length) &&
- !IS_SLASH(PREVIOUS)) {
- save = PREVIOUS;
- PREVIOUS = '\0';
- state->cwd_length--;
- }
-
- if (!IS_ABSOLUTE_PATH(state->cwd, state->cwd_length)) {
- state->cwd[state->cwd_length++] = save;
- state->cwd[state->cwd_length] = '\0';
- } else {
- PREVIOUS = '\0';
- state->cwd_length--;
- }
- } else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
- state->cwd = (char *) realloc(state->cwd,
state->cwd_length+ptr_length+1+1);
+ while (IS_ABSOLUTE_PATH(state->cwd, state->cwd_length)
&&
+ !IS_SLASH(PREVIOUS)) {
+ save = PREVIOUS;
+ PREVIOUS = '\0';
+ state->cwd_length--;
+ }
+
+ if (!IS_ABSOLUTE_PATH(state->cwd, state->cwd_length)) {
+ state->cwd[state->cwd_length++] = save;
+ state->cwd[state->cwd_length] = '\0';
+ } else {
+ PREVIOUS = '\0';
+ state->cwd_length--;
+ }
+ } else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
+ state->cwd = (char *) realloc(state->cwd,
state->cwd_length+ptr_length+1+1);
#ifdef TSRM_WIN32
- /* Windows 9x will consider C:\\Foo as a network path. Avoid
it. */
- if ((state->cwd[state->cwd_length-1]!='\\' &&
state->cwd[state->cwd_length-1]!='/') ||
- IsDBCSLeadByte(state->cwd[state->cwd_length-2])) {
- state->cwd[state->cwd_length++] = DEFAULT_SLASH;
- }
+ /* Windows 9x will consider C:\\Foo as a network path.
Avoid it. */
+ if ((state->cwd[state->cwd_length-1]!='\\' &&
state->cwd[state->cwd_length-1]!='/') ||
+
IsDBCSLeadByte(state->cwd[state->cwd_length-2])) {
+ state->cwd[state->cwd_length++] =
DEFAULT_SLASH;
+ }
#elif defined(NETWARE)
- /* If the token is a volume name, it will have colon at the end -- so, no
slash before it */
- if (ptr[ptr_length-1] != ':') {
- state->cwd[state->cwd_length++] = DEFAULT_SLASH;
- }
+ /* If the token is a volume name, it will have colon
at the end -- so, no slash before it */
+ if (ptr[ptr_length-1] != ':') {
+ state->cwd[state->cwd_length++] =
DEFAULT_SLASH;
+ }
#else
- state->cwd[state->cwd_length++] = DEFAULT_SLASH;
+ state->cwd[state->cwd_length++] = DEFAULT_SLASH;
#endif
- memcpy(&state->cwd[state->cwd_length], ptr, ptr_length+1);
- state->cwd_length += ptr_length;
+ memcpy(&state->cwd[state->cwd_length], ptr,
ptr_length+1);
+ state->cwd_length += ptr_length;
+ }
+ ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
}
- ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
- }
- if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) {
- state->cwd = (char *) realloc(state->cwd, state->cwd_length+1+1);
- state->cwd[state->cwd_length] = DEFAULT_SLASH;
- state->cwd[state->cwd_length+1] = '\0';
- state->cwd_length++;
+ if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) {
+ state->cwd = (char *) realloc(state->cwd,
state->cwd_length+1+1);
+ state->cwd[state->cwd_length] = DEFAULT_SLASH;
+ 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)) {
Index: php4/main/main.c
diff -u php4/main/main.c:1.512.2.17 php4/main/main.c:1.512.2.18
--- php4/main/main.c:1.512.2.17 Sat Mar 15 19:03:26 2003
+++ php4/main/main.c Mon Mar 17 08:50:22 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.512.2.17 2003/03/16 00:03:26 helly Exp $ */
+/* $Id: main.c,v 1.512.2.18 2003/03/17 13:50:22 wez Exp $ */
/* {{{ includes
*/
@@ -1568,7 +1568,11 @@
{
zend_file_handle *prepend_file_p, *append_file_p;
zend_file_handle prepend_file, append_file;
+#if HAVE_BROKEN_GETCWD
+ int old_cwd_fd;
+#else
char *old_cwd;
+#endif
char *old_primary_file_path = NULL;
int retval = 0;
@@ -1576,9 +1580,11 @@
if (php_handle_special_queries(TSRMLS_C)) {
return 0;
}
-#define OLD_CWD_SIZE 4096
+#ifndef HAVE_BROKEN_GETCWD
+# define OLD_CWD_SIZE 4096
old_cwd = do_alloca(OLD_CWD_SIZE);
old_cwd[0] = '\0';
+#endif
zend_try {
#ifdef PHP_WIN32
@@ -1589,7 +1595,12 @@
if (primary_file->type == ZEND_HANDLE_FILENAME
&& primary_file->filename) {
+#if HAVE_BROKEN_GETCWD
+ /* this looks nasty to me */
+ old_cwd_fd = open(".", 0);
+#else
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
+#endif
VCWD_CHDIR_FILE(primary_file->filename);
}
@@ -1641,10 +1652,15 @@
} zend_end_try();
+#if HAVE_BROKEN_GETCWD
+ fchdir(old_cwd_fd);
+ close(old_cwd_fd);
+#else
if (old_cwd[0] != '\0') {
VCWD_CHDIR(old_cwd);
}
free_alloca(old_cwd);
+#endif
return retval;
}
/* }}} */
Index: php4/main/safe_mode.c
diff -u php4/main/safe_mode.c:1.51.2.3 php4/main/safe_mode.c:1.51.2.4
--- php4/main/safe_mode.c:1.51.2.3 Thu Jan 9 17:34:27 2003
+++ php4/main/safe_mode.c Mon Mar 17 08:50:23 2003
@@ -15,7 +15,7 @@
| Author: Rasmus Lerdorf <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: safe_mode.c,v 1.51.2.3 2003/01/09 22:34:27 iliaa Exp $ */
+/* $Id: safe_mode.c,v 1.51.2.4 2003/03/17 13:50:23 wez Exp $ */
#include "php.h"
@@ -125,6 +125,11 @@
VCWD_REALPATH(filename, path);
*s = DEFAULT_SLASH;
} else {
+ /* Under Solaris, getcwd() can fail if there are no
+ * read permissions on a component of the path, even
+ * though it has the required x permissions */
+ path[0] = '.';
+ path[1] = '\0';
VCWD_GETCWD(path, sizeof(path));
}
} /* end CHECKUID_ALLOW_ONLY_DIR */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php