dex4er / fakechroot

gives a fake chroot environment
GNU Lesser General Public License v2.1
295 stars 73 forks source link

Path expansion before stat(...) #81

Open t-bltg opened 3 years ago

t-bltg commented 3 years ago

I get different behaviors with and without fakechroot, when issuing a stat on a non-traversable path:

case 1

~$ sudo /usr/sbin/chroot /
/# test -e __non_existent_dir__/../usr; echo $?
1

case 2

~$ /usr/bin/fakechroot /usr/sbin/chroot /
/$ test -e __non_existent_dir__/../usr; echo $?
0

test -e (in test.c from coreutils) is calling stat(...) without any expansion.

I believe that calling dedotdot(...) from expand_chroot_path in stat.c is responsible for this.

An ugly patch on the fly using a new environment variable FAKECHROOT_NODEDOTDOT fixes the issue:

--- src/dedotdot.c  2021-01-02 17:36:49.967851000 +0000
+++ src/dedotdot.c  2021-01-07 21:27:09.163077450 +0000
@@ -51,9 +51,11 @@
  */

 #include <string.h>
+#include <stdlib.h>

 LOCAL void dedotdot(char * file)
 {
+    if (getenv("FAKECHROOT_NODEDOTDOT")) return;
     char c, *cp, *cp2;
     int l;

https://github.com/dex4er/fakechroot/pull/46 seems related ...