proot-me / proot

chroot, mount --bind, and binfmt_misc without privilege/setup for Linux
https://proot-me.github.io
GNU General Public License v2.0
1.96k stars 369 forks source link

Fix test-0cf405b0 for newer versions of glibc. #342

Closed KimonHoffmann closed 1 year ago

KimonHoffmann commented 1 year ago

Newer versions of glibc apparently enforce argv to contain at least one argument, regardless of what what passed to execlp(). This behavioral change resulted in test-0cf405b0 performing an endless loop.

This commit addresses this problem by setting an environment variable to indicate, whether the execlp() call has already been performed.

oxr463 commented 1 year ago

@KimonHoffmann can you provide a link to the documentation?

KimonHoffmann commented 1 year ago

I could not find any official documentation explicitly stating this, but the function signature documented on the manpage as well as in the official GLIBC documentation implies argc to be greater than, or equal to 1, which is also mirrored by the current GLIBC implementation.

Because of this the condition for argc == 0 never holds and the test results in an infinite loop.

I think my fix is unproblematic, because the test was added to assert that proot does not crash when execlp is called with the NULL pointer for arg and argc being 0 was just a convenient way to distinguish the parent and child processes.

oxr463 commented 1 year ago

Thanks for your contribution! I've gone ahead and rebased this change onto the master branch. I'm going to close this PR.

KimonHoffmann commented 1 year ago

Perfect, thanks!