Skip to content

Commit

Permalink
PROOT_L2S_DIR has been fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
green-green-avk committed Feb 15, 2020
1 parent fc1d2d2 commit a99ddca
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/extension/link2symlink/link2symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

#define STRLEN(V) (sizeof(V) - 1)

/* .XXXX.YYYY */
#define SUFFIX_LEN 10

#ifdef USERLAND
#define PREFIX ".proot.l2s."
#endif
#ifndef USERLAND
#else
#define PREFIX ".l2s."
#endif
#define DELETED_SUFFIX " (deleted)"
Expand Down Expand Up @@ -68,7 +70,7 @@ static int move_and_symlink_path(Tracee *tracee, Reg sysarg)
int status;
int link_count;
int first_link = 1;
int intermediate_suffix = 1;
uint32_t intermediate_suffix = 0;

/* Note: this path was already canonicalized. */
size = read_string(tracee, original, peek_reg(tracee, CURRENT, sysarg), PATH_MAX);
Expand Down Expand Up @@ -101,23 +103,23 @@ static int move_and_symlink_path(Tracee *tracee, Reg sysarg)
first_link = 0;
} else {
/* compute new name */
name = strrchr(original,'/');
name = strrchr(original, '/');
if (name == NULL)
name = original;
else
name++;

l2s_directory = env_PROOT_L2S_DIR;
if (l2s_directory != NULL && l2s_directory[0]) {
if (STRLEN(PREFIX) + strlen(l2s_directory) + (strlen(original) - strlen(name)) + 6 >= PATH_MAX)
if (l2s_directory != NULL && l2s_directory[0] != '\0') {
if (strlen(l2s_directory) + strlen(name) + STRLEN(PREFIX) + SUFFIX_LEN + 2 >= PATH_MAX)
return -ENAMETOOLONG;

strcpy(intermediate, l2s_directory);
if (l2s_directory[strlen(l2s_directory) - 1] != '/') {
strcat(intermediate, "/");
}
} else {
if (STRLEN(PREFIX) + strlen(original) + 5 >= PATH_MAX)
if (strlen(original) + STRLEN(PREFIX) + SUFFIX_LEN + 1 >= PATH_MAX)
return -ENAMETOOLONG;

strncpy(intermediate, original, strlen(original) - strlen(name));
Expand All @@ -130,9 +132,10 @@ static int move_and_symlink_path(Tracee *tracee, Reg sysarg)
if (first_link) {
/*Move the original content to the new path. */
do {
sprintf(new_intermediate, "%s%04d", intermediate, intermediate_suffix);
sprintf(new_intermediate, "%s.%04X", intermediate, intermediate_suffix);
if (intermediate_suffix == 0xFFFF) return -ENAMETOOLONG;
intermediate_suffix++;
} while ((access(new_intermediate,F_OK) != -1) && (intermediate_suffix < 1000));
} while (access(new_intermediate, F_OK) != -1);
strcpy(intermediate, new_intermediate);

strcpy(final, intermediate);
Expand Down Expand Up @@ -530,7 +533,9 @@ int link2symlink_callback(Extension *extension, ExtensionEvent event,
{ PR_renameat2, FILTER_SYSEXIT },
FILTERED_SYSNUM_END,
};
env_PROOT_L2S_DIR = getenv("PROOT_L2S_DIR");
const char *const dir = getenv("PROOT_L2S_DIR");
if (dir != NULL)
env_PROOT_L2S_DIR = realpath(dir, NULL);
extension->filtered_sysnums = filtered_sysnums;
return 0;
}
Expand Down

0 comments on commit a99ddca

Please sign in to comment.