Skip to content

Path expansion before stat(...) #81

@t-bltg

Description

@t-bltg

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;

#46 seems related ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions