Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Christian Stocker

Hi Dmitry


On 8.8.2008 17:52 Uhr, Dmitry Stogov wrote:

Hi,

The attached patch is going to fix the problem.


Works also on my OS X 10.4 box now. Thanks a lot for the effort (and if 
it brings a performance boost, even better :) )


chregu



It implements its own realpath() function, so we won't depend on system
anymore. It also improve realpath cache usage by caching intermediate
results.

I tested it on Linux and Windows only and it seems to work without
problems. It breaks one test related to clearstatcache() function, but
this break is expected.

Could you please test it.
Does it really fix the bug on FreeBSD?

Thanks. Dmitry.


Hannes Magnusson wrote:

On Thu, Aug 7, 2008 at 22:37, Arnaud Le Blanc [EMAIL PROTECTED] wrote:

virtual_file_ex() assumes that realpath() returns NULL when the file does not
exists. But BSD's realpath() will not return NULL if all
components *but the last* exist. So realpath(/foo/bar) will return /foo/bar
even if bar does not exists.

And that behavior is intended, but is sadly overwritten in ZTS :(

-Hannes


--
New Office Zurich Opening: http://liip.to/party
--
Liip AG  //  Feldstrasse 133 //  CH-8004 Zurich
Tel +41 43 500 39 81 // Mobile +41 76 561 88 60
www.liip.ch // blog.liip.ch // GnuPG 0x5CE1DECB


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Hannes Magnusson
On Fri, Aug 8, 2008 at 17:52, Dmitry Stogov [EMAIL PROTECTED] wrote:
 Hi,

 The attached patch is going to fix the problem.
 It implements its own realpath() function, so we won't depend on system
 anymore. It also improve realpath cache usage by caching intermediate
 results.

 I tested it on Linux and Windows only and it seems to work without
 problems. It breaks one test related to clearstatcache() function, but
 this break is expected.

 Could you please test it.
 Does it really fix the bug on FreeBSD?

Yup. But it introduces a new one.
realpath() no longer works as documented, now requiring all the
components to exist.

-Hannes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Dmitry Stogov

Where is it documented?

The realpath() implementation conforming to 4.4BSD and POSIX.1-2001 
requires file existence. With the patch it'll work in the same standard 
way on all systems.


Thanks. Dmitry.

Hannes Magnusson wrote:

On Fri, Aug 8, 2008 at 17:52, Dmitry Stogov [EMAIL PROTECTED] wrote:

Hi,

The attached patch is going to fix the problem.
It implements its own realpath() function, so we won't depend on system
anymore. It also improve realpath cache usage by caching intermediate
results.

I tested it on Linux and Windows only and it seems to work without
problems. It breaks one test related to clearstatcache() function, but
this break is expected.

Could you please test it.
Does it really fix the bug on FreeBSD?


Yup. But it introduces a new one.
realpath() no longer works as documented, now requiring all the
components to exist.

-Hannes


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Hannes Magnusson
On Sat, Aug 9, 2008 at 12:31, Dmitry Stogov [EMAIL PROTECTED] wrote:
 Where is it documented?

http://php.net/realpath
http://www.ipnom.com/FreeBSD-Man-Pages/realpath.3.html

-Hannes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Pierre Joye
hi all!

On Sat, Aug 9, 2008 at 12:41 PM, Hannes Magnusson
[EMAIL PROTECTED] wrote:
 On Sat, Aug 9, 2008 at 12:31, Dmitry Stogov [EMAIL PROTECTED] wrote:
 Where is it documented?

 http://php.net/realpath
 http://www.ipnom.com/FreeBSD-Man-Pages/realpath.3.html

On BSD systems realpath()  doesn't fail if only the last path
component doesn't exist, while other systems will return FALSE.

This behavior has genearated enough pain in the past to be dropped.
The key problem in php application is portability. I'm in favor of
dropping this BSD specific thing in 5.3+.

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Stefan Esser
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello Dmitry,

while you are at fixing realpath() it might be a good idea to fix the
../ nonsense.

What I mean is:

fopen(this_is_not_a_dir_but_a_file/../../../../../../../../etc/passwd,
r);

works because of realpath() and PHP's wrapper.

Same for

fopen(this_is_not_existing/../../../../../../../../etc/passwd, r);

Both is madness...


Stefan

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEUEARECAAYFAkidgR0ACgkQSuF5XhWr2nhovACXZpeATBITDai/M1wsCuavuZ3C
OgCgn46uM4XHwENW7si4aJzeNgnuTKg=
=QiYy
-END PGP SIGNATURE-

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] clearstatcache change

2008-08-09 Thread Arnaud Le Blanc
On Thursday 07 August 2008 11:33:02 Arnaud Le Blanc wrote:
 On Thursday 07 August 2008 01:50:06 Johannes Schlüter wrote:
  On Wed, 2008-08-06 at 21:00 +0200, Arnaud Le Blanc wrote:
 btw. I just noticed chroot() calls this
 realpath_cache_clean()..intentional?
 
  I'd assume that, as /foo inside a chroot is different from /foo
  outside...
 
Also some streams stuff uses the
  
 php_clear_stat_cache() func but those should propably use the
 realpatch_cache_del() instead and not blow away whole cache?
   
Yes, I think too.
I added that to your patch:
http://arnaud.lb.s3.amazonaws.com/clearstatcache_optional_params.patc
   h
   
:)
   
It also adds the filename argument to
clearstatcache([bool clear_realpath_cache[, filename]])
  
   I reply to myself, actually this may cause troubles to not clear the
   full cache in plain_wrapper.c :/ I updated the patch, just left the
   filename argument to clearstatcache().
 
  If you fix the arginfo like Hannes it's, good. If the name of the second
  parameter in the proto (filename) is the same as in the implementation
  (pathname) it might even be a bit better :-)
 
  johanes

 Commited :)


Hi,

I have noticed that there is no function to know the realpath cache usage 
(e.g. is the realpath cache full ? what files are in the cache ?)

I have written two functions:
realpath_cache_get_entries() which returns an array of entries in the cache, 
and realpath_cache_get_usage() which returns the cache size. The first one may 
also help in writing tests for the realpath cache.

http://arnaud.lb.s3.amazonaws.com/realpath_cache_funcs.patch

Can I add them ?

Regards,

Arnaud



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Dmitry Stogov

The improved patch fixes all the issues I found during testing.
However I wasn't able to test it on NETWARE and on Solaris with relative 
paths.


Please test it as much as possible.
I'm going to commit it on Tuesday in case of no objections.

Thanks. Dmitry.

Rasmus Lerdorf wrote:

Rasmus Lerdorf wrote:

Dmitry Stogov wrote:

Hi,

The attached patch is going to fix the problem.
It implements its own realpath() function, so we won't depend on system
anymore. It also improve realpath cache usage by caching intermediate
results.


Very nice. The intermediate caching is going to drastically reduce the
amount of memory we need for the cache. I have seen a number of cases
where sites had to increase the realpath cache size by quite a bit.


Oh, and on top of that we also get a big performance improvement for 
include_path misses since we no longer have to re-stat every component 
of the docroot on every miss.


-Rasmus
? TSRM/autom4te.cache
? TSRM/stamp-h1
? TSRM/tsrm_virtual_cwd-0.c
? TSRM/tsrm_virtual_cwd-1.c
? TSRM/tsrm_virtual_cwd-2.c
Index: NEWS
===
RCS file: /repository/php-src/NEWS,v
retrieving revision 1.2027.2.547.2.965.2.259
diff -u -p -d -r1.2027.2.547.2.965.2.259 NEWS
--- NEWS8 Aug 2008 18:46:20 -   1.2027.2.547.2.965.2.259
+++ NEWS9 Aug 2008 14:52:58 -
@@ -5,6 +5,8 @@ PHP 
 
 - Changed session_start() to return false when session startup fails. (Jani)
 
+- Added system independent realpth() implementation which caches intermediate
+  results in realpath-cache (Dmitry)
 - Added optional clear_realpath_cache and filename parameters to
   clearstatcache(). (Jani, Arnaud)
 - Added litespeed SAPI module. (George Wang)
@@ -21,8 +23,11 @@ PHP 
 - Fixed bug #45636 (fileinfo ext duplicate strndup). (Derick)
 - Fixed bug #45545 (DateInterval has 4 char limitation for ISO durations).
   (Derick)
+- Fixed bug #45044 (relative paths not resolved correctly). (Dmitry)
 - Fixed bug #44100 (Inconsistent handling of static array declarations with
   duplicate keys). (Dmitry)
+- Fixed bug #43817 (opendir() fails on Windows directories with parent
+  directory unaccessible). (Dmitry)
 - Fixed bug #43008 (php://filter uris ignore url encoded filternames and can't
   handle slashes). (Arnaud)
 
Index: TSRM/tsrm_virtual_cwd.c
===
RCS file: /repository/TSRM/tsrm_virtual_cwd.c,v
retrieving revision 1.74.2.9.2.35.2.7
diff -u -p -d -r1.74.2.9.2.35.2.7 tsrm_virtual_cwd.c
--- TSRM/tsrm_virtual_cwd.c 20 May 2008 07:41:35 -  
1.74.2.9.2.35.2.7
+++ TSRM/tsrm_virtual_cwd.c 9 Aug 2008 14:52:59 -
@@ -257,22 +257,6 @@ static void cwd_globals_dtor(virtual_cwd
 }
 /* }}} */
 
-static char *tsrm_strndup(const char *s, size_t length) /* {{{ */
-{
-char *p;
-
-p = (char *) malloc(length+1);
-if (!p) {
-return (char *)NULL;
-}
-if (length) {
-memcpy(p,s,length);
-}
-p[length]=0;
-return p;
-}
-/* }}} */
-
 CWD_API void virtual_cwd_startup(void) /* {{{ */
 {
char cwd[MAXPATHLEN];
@@ -431,9 +415,17 @@ CWD_API void realpath_cache_del(const ch
 }
 /* }}} */
 
-static inline void realpath_cache_add(const char *path, int path_len, const 
char *realpath, int realpath_len, time_t t TSRMLS_DC) /* {{{ */
+static inline void realpath_cache_add(const char *path, int path_len, const 
char *realpath, int realpath_len, int is_dir, time_t t TSRMLS_DC) /* {{{ */
 {
-   long size = sizeof(realpath_cache_bucket) + path_len + 1 + realpath_len 
+ 1;
+   long size = sizeof(realpath_cache_bucket) + path_len + 1;
+   int same = 1;
+   
+   if (realpath_len != path_len ||
+   memcmp(path, realpath, path_len) != 0) {
+   size += realpath_len + 1;
+   same = 0;
+   }
+
if (CWDG(realpath_cache_size) + size = 
CWDG(realpath_cache_size_limit)) {
realpath_cache_bucket *bucket = malloc(size);
unsigned long n;
@@ -442,9 +434,14 @@ static inline void realpath_cache_add(co
bucket-path = (char*)bucket + sizeof(realpath_cache_bucket);
memcpy(bucket-path, path, path_len+1);
bucket-path_len = path_len;
-   bucket-realpath = bucket-path + (path_len + 1);
-   memcpy(bucket-realpath, realpath, realpath_len+1);
+   if (same) {
+   bucket-realpath = bucket-path;
+   } else {
+   bucket-realpath = bucket-path + (path_len + 1);
+   memcpy(bucket-realpath, realpath, realpath_len+1);
+   }
bucket-realpath_len = realpath_len;
+   bucket-is_dir = is_dir;
bucket-expires = t + CWDG(realpath_cache_ttl);
n = bucket-key % (sizeof(CWDG(realpath_cache)) / 

Re: [PHP-DEV] [RFC] Zend Signal Handling

2008-08-09 Thread Arnaud Le Blanc
Hi,

As Lucas said the patch seems ready now, could someone please review the patch 
for inclusion ?

http://wiki.php.net/rfc/zendsignals

Changes that have been made:

- The patch has been ported to HEAD
- The patch now supports multithreaded environments, and fixes many problems 
on non-windows platforms when enabled.
- Extensions can use zend_signal() and zend_sigaction() so that all signals 
they declare will always be deferred in critical sections. PCNTL has been 
ported.
- There is now a zend.signal_check ini entry so that the checks made in 
zend_signal_deactivate() can be done in non-debug builds.
- Some code has been moved to process startup or global constructor routines.
- The patch moves some HANDLE_BLOCK/UNBLOCK in zend_alloc to protect more code

Regards,

Arnaud


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Pierre Joye
hi Dmitry,

On Sat, Aug 9, 2008 at 5:28 PM, Dmitry Stogov [EMAIL PROTECTED] wrote:
 The improved patch fixes all the issues I found during testing.
 However I wasn't able to test it on NETWARE and on Solaris with relative
 paths.

 Please test it as much as possible.

I run the test suite and the results can be seen here:

http://phpfi.com/341752

There is two failing for real path (Server 2008, Vista 64 and XP (32 and 64)):

Test realpath() function: basic functionality
[C:\Users\pierre\Documents\php-sdk\vc9\x86\php_5_3\ext\standard\tests\file\realpath_basic-win32.phpt]
realpath() with relative directory
[C:\Users\pierre\Documents\php-sdk\vc9\x86\php_5_3\ext\standard\tests\file\realpath_basic2.phpt]


Some other may fail because of a change in realpath behavior. I will
run them again without the patch and post again the affected tests.

 I'm going to commit it on Tuesday in case of no objections.

A FindClose is missing:

 +#ifdef TSRM_WIN32
 +   if (save  (hFind = FindFirstFile(path, data)) ==  
 INVALID_HANDLE_VALUE) {
if (use_realpath == CWD_REALPATH) {
 -   return 1;
 +   /* file not found */
 +   return -1;
}

.

 +   if (save) {
 +   directory = (data.dwFileAttributes   
 FILE_ATTRIBUTE_DIRECTORY) != 0;
 +   if (is_dir  !directory) {
 +   /* not a directory */

FindClose(hFind);

 +   return -1;
 +   }
 +   }
 +   tmp = tsrm_do_alloca(len+1, use_heap);
 +   memcpy(tmp, path, len+1);
 +#elif defined(NETWARE)
 +   save = 0;
 +   tmp = tsrm_do_alloca(len+1, use_heap);
 +   memcpy(tmp, path, len+1);
  #else

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Antony Dovgal

On 09.08.2008 19:28, Dmitry Stogov wrote:

The improved patch fixes all the issues I found during testing.
However I wasn't able to test it on NETWARE and on Solaris with relative 
paths.


Please test it as much as possible.
I'm going to commit it on Tuesday in case of no objections.


ext/standard/tests/file/clearstatcache_001.phpt fails with the patch applied.

--
Wbr, 
Antony Dovgal


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Antony Dovgal

On 09.08.2008 19:28, Dmitry Stogov wrote:

The improved patch fixes all the issues I found during testing.
However I wasn't able to test it on NETWARE and on Solaris with relative 
paths.


Please test it as much as possible.
I'm going to commit it on Tuesday in case of no objections.


These three tests fail on AIX *without* the patch and pass with it, 
so the patch seems to fix some issues indeed =)


ext/standard/tests/file/readlink_realpath_basic1.phpt
ext/standard/tests/file/readlink_realpath_basic2.phpt
ext/standard/tests/file/realpath_basic3.phpt

--
Wbr, 
Antony Dovgal


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] fix for a couple zend tests

2008-08-09 Thread Pierre Joye
hi!

Please find the patch as attachment. It fixes a couple of tests in
Zend (unset, heredoc).

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org
? bug38779.txt
Index: heredoc_005.phpt
===
RCS file: /repository/ZendEngine2/tests/heredoc_005.phpt,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 heredoc_005.phpt
--- heredoc_005.phpt12 Feb 2008 09:27:45 -  1.1.2.1
+++ heredoc_005.phpt9 Aug 2008 22:10:41 -
@@ -19,4 +19,4 @@ print {$x};
 
 ?
 --EXPECTF--
-Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting 
T_STRING or T_VARIABLE or T_NUM_STRING in %sheredoc_005.php on line 6
+Parse error: %s in %sheredoc_005.php on line 6
Index: heredoc_013.phpt
===
RCS file: /repository/ZendEngine2/tests/heredoc_013.phpt,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 heredoc_013.phpt
--- heredoc_013.phpt5 Apr 2008 22:29:08 -   1.1.2.1
+++ heredoc_013.phpt9 Aug 2008 22:10:55 -
@@ -9,4 +9,4 @@ MYLABEL;
 echo $var;
 ?
 --EXPECTF--
-Parse error: syntax error, unexpected T_START_HEREDOC in %sheredoc_013.php on 
line %d
+Parse error: %s in %sheredoc_013.php on line %d
Index: heredoc_014.phpt
===
RCS file: /repository/ZendEngine2/tests/heredoc_014.phpt,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 heredoc_014.phpt
--- heredoc_014.phpt5 Apr 2008 22:29:08 -   1.1.2.1
+++ heredoc_014.phpt9 Aug 2008 22:11:49 -
@@ -9,4 +9,4 @@ MYLABEL;
 echo $var;
 ?
 --EXPECTF--
-Parse error: syntax error, unexpected T_SL in %sheredoc_014.php on line %d
+Parse error: %s in %sheredoc_014.php on line %d
Index: unset.inc
===
RCS file: /repository/ZendEngine2/tests/unset.inc,v
retrieving revision 1.1
diff -u -p -r1.1 unset.inc
--- unset.inc   5 Oct 2004 06:53:39 -   1.1
+++ unset.inc   9 Aug 2008 20:32:35 -
@@ -1,3 +1,5 @@
-?php

-unset($x)

-?

+?php
+
+unset($x)
+
+?
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] [RFC] Zend Signal Handling

2008-08-09 Thread Rasmus Lerdorf

Arnaud Le Blanc wrote:

Hi,

As Lucas said the patch seems ready now, could someone please review the patch
for inclusion ?

http://wiki.php.net/rfc/zendsignals

Changes that have been made:

- The patch has been ported to HEAD
- The patch now supports multithreaded environments, and fixes many problems
on non-windows platforms when enabled.
- Extensions can use zend_signal() and zend_sigaction() so that all signals
they declare will always be deferred in critical sections. PCNTL has been
ported.
- There is now a zend.signal_check ini entry so that the checks made in
zend_signal_deactivate() can be done in non-debug builds.
- Some code has been moved to process startup or global constructor routines.
- The patch moves some HANDLE_BLOCK/UNBLOCK in zend_alloc to protect more code


And don't forget that there was no protection before at all in any SAPI 
other than Apache1 because HANDLE_BLOCK_INTERRUPTIONS() is a NOP on 
every other SAPI.  We effectively had no critial sections at all prior 
to this patch.


-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] include bug in 5.3

2008-08-09 Thread Rasmus Lerdorf

Stefan Esser wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello Dmitry,

while you are at fixing realpath() it might be a good idea to fix the
../ nonsense.

What I mean is:

fopen(this_is_not_a_dir_but_a_file/../../../../../../../../etc/passwd,
r);

works because of realpath() and PHP's wrapper.

Same for

fopen(this_is_not_existing/../../../../../../../../etc/passwd, r);


Dmitry, I think this is a good suggestion.  If any component of the 
path, other than the final one is not a directory, or if a component of 
the path doesn't exist, the realpath call should fail.  We're doing the 
stat on each one anyway, so checking the entry type shouldn't be an issue.


-Rasmus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] fix for a couple zend tests

2008-08-09 Thread Felipe Pena
Em Dom, 2008-08-10 às 01:31 +0200, Pierre Joye escreveu:
 hi!
 
 Please find the patch as attachment. It fixes a couple of tests in
 Zend (unset, heredoc).
 

Commited in 5_2, 5_3 and HEAD.

-- 
Regards,
Felipe Pena.


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php