From bca1fd8b47b0b4dc243cd7e3cd82a80bd37fb92b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 2 Aug 2009 11:04:46 +0200 Subject: [PATCH] xbps_file_chdir_exec: only chroot(3) if uid == 0 and /bin/sh exists. --HG-- extra : convert_revision : f07bf2f511d896fc6f6c731b5ef04f3eebcd2eaa --- lib/fexec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/fexec.c b/lib/fexec.c index c2595ec2033..aaa049105df 100644 --- a/lib/fexec.c +++ b/lib/fexec.c @@ -57,10 +57,11 @@ pfcexec(const char *path, const char *file, const char **argv) case 0: if (path != NULL) { /* - * If /bin/sh exists, chroot to destdir. - * Otherwise chdir to destdir. + * If root and /bin/sh exists chroot to + * 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) _exit(127); if (chdir("/") == -1)