X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=jail%2Ffs.c;h=f390180699f3d91fb53e01d594144ef9404ff440;hp=714fa879a042fa73a839fdc5949c235a783183fd;hb=def4c1b9766cf04cfdf42ada9e27fff228d0dc19;hpb=15ff8b1d09187c11b1331f811cc75b0dd2076827 diff --git a/jail/fs.c b/jail/fs.c index 714fa87..f390180 100644 --- a/jail/fs.c +++ b/jail/fs.c @@ -79,6 +79,29 @@ void mount_list_init(void) { avl_init(&mounts, avl_strcmp, false, NULL); } +static int add_script_interp(const char *path, const char *map, int size) +{ + int start = 2; + while (start < size && map[start] != '/') { + start++; + } + if (start >= size) { + ERROR("bad script interp (%s)", path); + return -1; + } + int stop = start + 1; + while (stop < size && map[stop] > 0x20 && map[stop] <= 0x7e) { + stop++; + } + if (stop >= size || (stop-start) > PATH_MAX) { + ERROR("bad script interp (%s)", path); + return -1; + } + char buf[PATH_MAX]; + strncpy(buf, map+start, stop-start); + return add_path_and_deps(buf, 1, -1, 0); +} + int add_path_and_deps(const char *path, int readonly, int error, int lib) { assert(path != NULL); @@ -93,7 +116,7 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib) if (path[0] == '/') { if (avl_find(&mounts, path)) return 0; - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY|O_CLOEXEC); if (fd == -1) return error; add_mount(path, readonly, error); @@ -135,6 +158,11 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib) goto out; } + if (map[0] == '#' && map[1] == '!') { + ret = add_script_interp(path, map, s.st_size); + goto out; + } + if (map[0] == ELFMAG0 && map[1] == ELFMAG1 && map[2] == ELFMAG2 && map[3] == ELFMAG3) { ret = elf_load_deps(path, map); goto out;