From fd7153fe5c81c4adb793938017776557a9def056 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 7 Mar 2013 18:07:47 +0100 Subject: [PATCH] lib/external/fexec.c: error out if chroot/chdir fails, ignore target_arch. --- lib/external/fexec.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/external/fexec.c b/lib/external/fexec.c index 78dccb08..fb90ee9d 100644 --- a/lib/external/fexec.c +++ b/lib/external/fexec.c @@ -42,7 +42,6 @@ static int pfcexec(struct xbps_handle *xhp, const char *file, const char **argv) { pid_t child; - const char *tarch; int status; child = vfork(); @@ -52,12 +51,17 @@ 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. */ - tarch = getenv("XBPS_TARGET_ARCH"); if (strcmp(xhp->rootdir, "/")) { - if (!tarch && geteuid() == 0 && access("bin/sh", X_OK) == 0) { - if (chroot(xhp->rootdir) == 0) { - if (chdir("/") == -1) - _exit(129); + if (geteuid() == 0 && access("bin/sh", X_OK) == 0) { + if (chroot(xhp->rootdir) == -1) { + xbps_dbg_printf(xhp, "%s: chroot() " + "failed: %s\n", *argv, strerror(errno)); + _exit(errno); + } + if (chdir("/") == -1) { + xbps_dbg_printf(xhp, "%s: chdir() " + "failed: %s\n", *argv, strerror(errno)); + _exit(errno); } } }