delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/23/14:51:21

Message-ID: <3E305621.3000704@mif.vu.lt>
Date: Thu, 23 Jan 2003 21:52:49 +0100
From: Laurynas Biveinis <laurynas DOT biveinis AT mif DOT vu DOT lt>
Organization: VU MIF
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130
X-Accept-Language: lt, en, en-us
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com, Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Subject: Re: [Fwd: Bugs in __solve_symlinks]
References: <3E270365 DOT 372459D1 AT phekda DOT freeserve DOT co DOT uk> <3E273A88 DOT 6050403 AT mif DOT vu DOT lt> <3E273F69 DOT F42991B2 AT phekda DOT freeserve DOT co DOT uk> <3E28677A DOT 7070804 AT mif DOT vu DOT lt> <3E29412E DOT DD1EDF2D AT phekda DOT freeserve DOT co DOT uk>
In-Reply-To: <3E29412E.DD1EDF2D@phekda.freeserve.co.uk>
X-OriginalArrivalTime: 23 Jan 2003 19:50:56.0848 (UTC) FILETIME=[BEDB7500:01C2C318]
Reply-To: djgpp-workers AT delorie DOT com

Richard Dawe wrote:
> Hello.
> 
> Laurynas Biveinis wrote:
> 
>>>    HERE=`pwd`
>>>    ln -s /dev/env/FOO link
>>>    export FOO=../../somefile
>>>    echo Hello > $FOO
>>>    cat link
>>>    cd ..
>>>    cat link
> 
> 
> Oops, obviously the last line should be:
> 
>     cat <directory>/link

Indeed. Now I was able to reproduce and fix the bug. Patch below 
commited. Can you check if shell commands you've described are working 
now? Also, here is the addition to the testsuite for the record. It is 
not commited yet because of many unrelated changes to the testsuite I've 
made.

    setenv("SYMTEST", "../../Makefile", 1);
    chdir("dir1/dir2");
    symlink("/dev/env/SYMTEST", "linkSYMTEST");
    test_success("linkSYMTEST", "../../Makefile");
    chdir("..");
    test_success("dir2/linkSYMTEST", "../Makefile");
    chdir("..");
    unsetenv("SYMTEST");

And the patch:

Index: djgpp/src/libc/compat/unistd/xsymlink.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/compat/unistd/xsymlink.c,v
retrieving revision 1.7
diff -u -p -r1.7 xsymlink.c
--- djgpp/src/libc/compat/unistd/xsymlink.c	17 Jan 2003 19:48:12 -0000	1.7
+++ djgpp/src/libc/compat/unistd/xsymlink.c	23 Jan 2003 19:44:07 -0000
@@ -7,8 +7,10 @@
  /* resolves only last filename component and one symlink level.)     */

  #include <libc/stubs.h>
+#include <libc/dosio.h>
  #include <libc/symlink.h>
  #include <errno.h>
+#include <go32.h>
  #include <limits.h>
  #include <stdio.h>
  #include <unistd.h>
@@ -79,7 +81,24 @@ int __solve_symlinks(const char * __syml
              done_something = 1;
              link_level++;
              fn_buf[bytes_copied] = '\0';
-            strcpy(resolved, fn_buf);
+            /* We can get /dev/env/SOMEVARIABLE as a symlink target. Do not
+               restart processing in this case, but substitute 
/dev/env/SOMEVARIABLE
+               with expanded SOMEVARIABLE.  Note that SOMEVARIABLE may 
expand to
+               either relative or absolute path. */
+            if (strncmp(fn_buf, "/dev/env/", strlen("/dev/env/")))
+            	strcpy(resolved, fn_buf);
+            else
+            {
+            	/* Fill `resolved' with expanded env variable. Do this by
+            	   calling _put_path(). TODO: It could be nice to factor
+            	   out some code from _put_path2() to separate function to 
expand
+            	   /dev/env/FOO once, i.e. do not recurse as _put_path2() 
does.
+            	   However, it is not completely trivial, so current 
implementation
+            	   takes a performance hit there. */
+            	_put_path(fn_buf);
+            	dosmemget(__tb, FILENAME_MAX, resolved);
+            }
+
              /* FIXME: does absolute path check below work with 
chroot()? */
              if (((bytes_copied > 2) &&  (resolved[1] == ':')) ||
                  ((bytes_copied > 0) && ((resolved[0] == '/') ||



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019