Certainly. The problem with the old code was quite simple. Suppose we have a 
file 'original_file' and we make a symlink to it and call it 'my_symlink'. If 
inside my PHP code I were to do: unlink('my_symlink');, instead of deleting 
the symlink, the unlink function would remove the original file, which is 
extremely bad behaviour, wouldn't you agree?
The reason why this is happening is because virtual_file_ex() does an 
equivalent of realpath(), which resolves symlinks, thus the file 
new_state.cwd is pointing to is actually the original file and not the 
symlink the user wants to remove.

The virtual_link function only resolves the path and does not attempt the 
resolve the symlinks, hence the file, which is removed is the symlink and not 
the original file.

Ilia


On November 4, 2002 03:15 am, Andi Gutmans wrote:
> I don't understand what you're doing here. Can you please next time post
> this kind of stuff before you submit a fix?
> What is virtual_link()? Do you realize it returns a pointer to the stack
> when the stack is gone already?
> Can you please explain what was wrong with the code before you added it?
>
> Andi
>
> At 05:19 AM 11/4/2002 +0000, Ilia Alshanetsky wrote:
> >iliaa           Mon Nov  4 00:19:05 2002 EDT
> >
> >   Modified files:
> >     /TSRM       tsrm_virtual_cwd.c
> >   Log:
> >   Fix bug #20235.
> >
> >
> >Index: TSRM/tsrm_virtual_cwd.c
> >diff -u TSRM/tsrm_virtual_cwd.c:1.36 TSRM/tsrm_virtual_cwd.c:1.37
> >--- TSRM/tsrm_virtual_cwd.c:1.36        Tue Oct 29 02:32:52 2002
> >+++ TSRM/tsrm_virtual_cwd.c     Mon Nov  4 00:19:05 2002
> >@@ -17,7 +17,7 @@
> >    
> > +----------------------------------------------------------------------+
> > */
> >
> >-/* $Id: tsrm_virtual_cwd.c,v 1.36 2002/10/29 07:32:52 shane Exp $ */
> >+/* $Id: tsrm_virtual_cwd.c,v 1.37 2002/11/04 05:19:05 iliaa Exp $ */
> >
> >  #include <sys/types.h>
> >  #include <sys/stat.h>
> >@@ -727,7 +727,7 @@
> >         int retval;
> >         char *p;
> >
> >-       p = virtual_link(path, strlen(path) TSRMLS_CC);
> >+       p = virtual_link((char *)path, strlen(path) TSRMLS_CC);
> >         retval = lstat(p, buf);
> >
> >         return retval;
> >@@ -736,15 +736,12 @@
> >
> >  CWD_API int virtual_unlink(const char *path TSRMLS_DC)
> >  {
> >-       cwd_state new_state;
> >         int retval;
> >+       char *resolved_path;
> >
> >-       CWD_STATE_COPY(&new_state, &CWDG(cwd));
> >-       virtual_file_ex(&new_state, path, NULL);
> >+       resolved_path = virtual_link((char *)path, strlen(path)
> > TSRMLS_CC); +       retval = unlink(resolved_path);
> >
> >-       retval = unlink(new_state.cwd);
> >-
> >-       CWD_STATE_FREE(&new_state);
> >         return retval;
> >  }
> >
> >
> >
> >
> >--
> >PHP CVS Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to