Make xbps_file_chdir_exec() change root directory if /bin/sh exists.
If /bin/sh is not there, fall back to chdir(destdir) as before. --HG-- extra : convert_revision : 7506a8db97346dbf45292e4c46b9d8ecc384162a
This commit is contained in:
parent
581e908793
commit
3e9e342f74
1 changed files with 18 additions and 5 deletions
23
lib/fexec.c
23
lib/fexec.c
|
@ -41,8 +41,9 @@ static int vfcexec(const char *, int, const char *, va_list);
|
||||||
static int pfcexec(const char *, const char *, const char **);
|
static int pfcexec(const char *, const char *, const char **);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fork, then change current working directory to path and
|
* Fork, then if /bin/sh exists change root directory to
|
||||||
* execute the command and arguments in the argv array.
|
* path; otherwise just change current working directory.
|
||||||
|
* Execute the command and arguments in the argv array.
|
||||||
* wait for the command to finish, then return the exit status.
|
* wait for the command to finish, then return the exit status.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
@ -54,9 +55,21 @@ pfcexec(const char *path, const char *file, const char **argv)
|
||||||
child = vfork();
|
child = vfork();
|
||||||
switch (child) {
|
switch (child) {
|
||||||
case 0:
|
case 0:
|
||||||
if ((path != NULL) && (chdir(path) < 0))
|
if (path != NULL) {
|
||||||
_exit(127);
|
/*
|
||||||
|
* If /bin/sh exists, chroot to destdir.
|
||||||
|
* Otherwise chdir to destdir.
|
||||||
|
*/
|
||||||
|
if (access("./bin/sh", R_OK) == 0) {
|
||||||
|
if (chroot(path) == -1)
|
||||||
|
_exit(127);
|
||||||
|
if (chdir("/") == -1)
|
||||||
|
_exit(127);
|
||||||
|
} else {
|
||||||
|
if (chdir(path) == -1)
|
||||||
|
_exit(127);
|
||||||
|
}
|
||||||
|
}
|
||||||
(void)execvp(file, (char ** const)argv);
|
(void)execvp(file, (char ** const)argv);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue