From 0a082a82c39c3fbeccd447ca8bbe2964e7279092 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 17 Nov 2012 11:44:14 +0100 Subject: [PATCH] xbps_file_exec: don't fail if chroot(2) fails (due to EPERM). --- lib/external/fexec.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/external/fexec.c b/lib/external/fexec.c index 663f0428..5ef2a662 100644 --- a/lib/external/fexec.c +++ b/lib/external/fexec.c @@ -50,15 +50,13 @@ pfcexec(struct xbps_handle *xhp, const char *file, const char **argv) /* * If rootdir != / and uid==0 and bin/sh exists, * change root directory and exec command. - * - * It's assumed that cwd is the target rootdir. */ if (strcmp(xhp->rootdir, "/")) { - if (getuid() == 0 && access("bin/sh", X_OK) == 0) { - if (chroot(xhp->rootdir) == -1) - _exit(128); - if (chdir("/") == -1) - _exit(129); + if (geteuid() == 0 && access("bin/sh", X_OK) == 0) { + if (chroot(xhp->rootdir) == 0) { + if (chdir("/") == -1) + _exit(129); + } } } (void)execv(file, __UNCONST(argv));