Skip to content

Commit 52afebc

Browse files
committed
Don't prefix APPDIR path
1 parent ca6ad69 commit 52afebc

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/hooks/redirect_path.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ char* redirect_path_full(const char* pathname, int check_parent, int only_if_abs
9292
if (only_if_absolute && pathname[0] != '/') {
9393
return strdup(pathname);
9494
}
95-
95+
9696
char* appdir_env = getenv(APPRUN_ENV_APPDIR);
9797
if (appdir_env == NULL) {
9898
return strdup(pathname);
@@ -110,9 +110,14 @@ char* redirect_path_full(const char* pathname, int check_parent, int only_if_abs
110110
if (strncmp(pathname, apprun_path_mappings[i]->path, strlen(apprun_path_mappings[i]->path)) == 0) {
111111
memset(redirected_pathname, 0, PATH_MAX);
112112

113-
strcat(redirected_pathname, appdir_env);
114-
strcat(redirected_pathname, apprun_path_mappings[i]->mapping);
115-
strcat(redirected_pathname, pathname + strlen(apprun_path_mappings[i]->path));
113+
const char* mapping = apprun_path_mappings[i]->mapping;
114+
const char* path_postfix = pathname + strlen(apprun_path_mappings[i]->path);
115+
116+
strcat(redirected_pathname, mapping);
117+
if (mapping[strlen(mapping) - 1] != '/' && path_postfix[0] != '/')
118+
strcat(redirected_pathname, "/");
119+
120+
strcat(redirected_pathname, path_postfix);
116121

117122
ret = _access(redirected_pathname, F_OK);
118123
if (ret == 0 || errno == ENOTDIR) { // ENOTDIR is OK because it exists at least

test/hooks/wrapper_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ void setup_wrapper() {
7272
void test_path_mappings() {
7373
fprintf(stdout, "Test path mappings: ");
7474

75-
set_private_env(APPRUN_ENV_APPDIR, "/");
76-
set_private_env("APPRUN_PATH_MAPPINGS", "/missing_path:bin/;/missing_path:usr/;");
75+
set_private_env("APPRUN_PATH_MAPPINGS", "/missing_path:/bin/;/missing_path:/usr/;");
7776

7877
assert_command_succeed(system("/usr/bin/stat /missing_path/bash >> /dev/null"));
7978
assert_command_succeed(system("/usr/bin/stat /missing_path/bin/stat >> /dev/null"));

0 commit comments

Comments
 (0)