diff options
| author | Yip Coekjan <69834864+Coekjan@users.noreply.github.com> | 2024-07-05 17:02:09 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-05 11:02:09 +0200 |
| commit | 6ac3716594c5611b6c0b24be0cddc7faf4cc7cdc (patch) | |
| tree | 33125910bf8e0d8d65d7b480ef560d69dab14a4c /src | |
| parent | 42bad3ea6b33be5285f5c03fd42838c7810bf789 (diff) | |
| download | box64-6ac3716594c5611b6c0b24be0cddc7faf4cc7cdc.tar.gz box64-6ac3716594c5611b6c0b24be0cddc7faf4cc7cdc.zip | |
Should not follow symlinks on file path resolution (#1644)
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 2 | ||||
| -rw-r--r-- | src/include/fileutils.h | 4 | ||||
| -rw-r--r-- | src/tools/fileutils.c | 31 | ||||
| -rw-r--r-- | src/wrapped/wrappedlibc.c | 6 |
4 files changed, 31 insertions, 12 deletions
diff --git a/src/core.c b/src/core.c index f31efadd..047d1d17 100644 --- a/src/core.c +++ b/src/core.c @@ -1930,7 +1930,7 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf PrintCollection(&my_context->box64_path, "BOX64 BIN PATH"); // lets build argc/argv stuff printf_log(LOG_INFO, "Looking for %s\n", prog); - my_context->argv[0] = ResolveFile(prog, &my_context->box64_path); + my_context->argv[0] = ResolveFileSoft(prog, &my_context->box64_path); // check if box86 is present { my_context->box86path = box_strdup(my_context->box64path); diff --git a/src/include/fileutils.h b/src/include/fileutils.h index 2e983c74..858c6324 100644 --- a/src/include/fileutils.h +++ b/src/include/fileutils.h @@ -10,8 +10,10 @@ // 0 : doesn't exist, 1: Does exist int FileExist(const char* filename, int flags); -// find a file, using Path if needed +// find a file, using Path if needed, resolving symlinks char* ResolveFile(const char* filename, path_collection_t* paths); +// find a file, using Path if needed, NOT resolving symlinks +char* ResolveFileSoft(const char* filename, path_collection_t* paths); // 1: if file is an x86 elf, 0: if not (or not found) int FileIsX86ELF(const char* filename); diff --git a/src/tools/fileutils.c b/src/tools/fileutils.c index 327f798f..11dc6905 100644 --- a/src/tools/fileutils.c +++ b/src/tools/fileutils.c @@ -42,11 +42,19 @@ int FileExist(const char* filename, int flags) return 1; } -char* ResolveFile(const char* filename, path_collection_t* paths) -{ +static char* ResolvePathInner(const char* path, int resolve_symlink) { + if (resolve_symlink) { + return box_realpath(path, NULL); + } else { + return box_strdup(path); + } +} + +static char* ResolveFileInner(const char* filename, path_collection_t* paths, int resolve_symlink) { char p[MAX_PATH]; - if(filename[0]=='/') - return box_strdup(filename); + if(filename[0]=='/') { + return ResolvePathInner(filename, resolve_symlink); + } for (int i=0; i<paths->size; ++i) { if(paths->paths[i][0]!='/') { // not an absolute path... @@ -57,11 +65,20 @@ char* ResolveFile(const char* filename, path_collection_t* paths) } else strcpy(p, paths->paths[i]); strcat(p, filename); - if(FileExist(p, IS_FILE)) - return box_realpath(p, NULL); + if(FileExist(p, IS_FILE)) { + return ResolvePathInner(p, resolve_symlink); + } } - return box_strdup(filename); //NULL; + return ResolvePathInner(filename, resolve_symlink); +} + +char* ResolveFile(const char* filename, path_collection_t* paths) { + return ResolveFileInner(filename, paths, 1); +} + +char* ResolveFileSoft(const char* filename, path_collection_t* paths) { + return ResolveFileInner(filename, paths, 0); } int FileIsX64ELF(const char* filename) diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 76ac38f8..7a3964b8 100644 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -2270,7 +2270,7 @@ EXPORT int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], ch EXPORT int32_t my_execvp(x64emu_t* emu, const char* path, char* const argv[]) { // need to use BOX64_PATH / PATH here... - char* fullpath = ResolveFile(path, &my_context->box64_path); + char* fullpath = ResolveFileSoft(path, &my_context->box64_path); // use fullpath... int self = isProcSelf(fullpath, "exe"); int x64 = FileIsX64ELF(fullpath); @@ -2387,7 +2387,7 @@ EXPORT int32_t my_execle(x64emu_t* emu, const char* path) EXPORT int32_t my_execlp(x64emu_t* emu, const char* path) { // need to use BOX64_PATH / PATH here... - char* fullpath = ResolveFile(path, &my_context->box64_path); + char* fullpath = ResolveFileSoft(path, &my_context->box64_path); // use fullpath... int self = isProcSelf(fullpath, "exe"); int x64 = FileIsX64ELF(fullpath); @@ -2465,7 +2465,7 @@ EXPORT int32_t my_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path, const posix_spawn_file_actions_t *actions, const posix_spawnattr_t* attrp, char* const argv[], char* const envp[]) { // need to use BOX64_PATH / PATH here... - char* fullpath = ResolveFile(path, &my_context->box64_path); + char* fullpath = ResolveFileSoft(path, &my_context->box64_path); // use fullpath... int self = isProcSelf(fullpath, "exe"); int x64 = FileIsX64ELF(fullpath); |