8000 Should not follow symlinks on `argv[0]` path resolution by Coekjan · Pull Request #1644 · ptitSeb/box64 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Should not follow symlinks on argv[0] path resolution #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/include/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 24 additions & 7 deletions src/tools/fileutils.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
0