xbps_file_chdir_exec: only chroot(3) if uid == 0 and /bin/sh exists.

--HG--
extra : convert_revision : f07bf2f511d896fc6f6c731b5ef04f3eebcd2eaa
This commit is contained in:
Juan RP 2009-08-02 11:04:46 +02:00
parent 67be65f444
commit bca1fd8b47

View file

@ -57,10 +57,11 @@ pfcexec(const char *path, const char *file, const char **argv)
case 0: case 0:
if (path != NULL) { if (path != NULL) {
/* /*
* If /bin/sh exists, chroot to destdir. * If root and /bin/sh exists chroot to
* Otherwise chdir to destdir. * destdir and exec the command. Otherwise
* just change CWD to destdir.
*/ */
if (access("./bin/sh", R_OK) == 0) { if (getuid() == 0 && access("./bin/sh", R_OK) == 0) {
if (chroot(path) == -1) if (chroot(path) == -1)
_exit(127); _exit(127);
if (chdir("/") == -1) if (chdir("/") == -1)