Skip to content

Commit

Permalink
Checking readlink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ex-Origin committed Feb 28, 2022
1 parent d3816e8 commit 250980a
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,36 @@ int handle_file_IO(int pid, struct ptrace_syscall_info *info)
memset(path_buf, 0, sizeof(path_buf));
snprintf(path_buf, sizeof(path_buf) - 1, "/proc/%d/fd/%lld", pid, info->entry.args[0]);
memset(path, 0, sizeof(path));
readlink(path_buf, path, sizeof(path) - 1);
existed = 0;
for (i = 0; existed == 0 && i < node_count; i++)
if (readlink(path_buf, path, sizeof(path) - 1) != -1)
{
if (strcmp(path, path_lists[i]) == 0)
existed = 0;
for (i = 0; existed == 0 && i < node_count; i++)
{
existed = 1;
if (strcmp(path, path_lists[i]) == 0)
{
existed = 1;
}
}
}
if (existed == 0)
{
// Extend
if (node_count + 1 > node_max)
if (existed == 0)
{
result = realloc(path_lists, sizeof(char *) * node_max * 2);
// Extend
if (node_count + 1 > node_max)
{
result = realloc(path_lists, sizeof(char *) * node_max * 2);
CHECK(result != NULL);
node_max = node_max * 2;
path_lists = (char **)result;
}
result = strdup(path);
CHECK(result != NULL);
node_max = node_max * 2;
path_lists = (char **)result;
path_lists[node_count] = result;
node_count++;
printf("[TRACE INFO]: %s\n", path);
}
result = strdup(path);
CHECK(result != NULL);
path_lists[node_count] = result;
node_count++;
printf("[TRACE INFO]: %s\n", path);
}
else
{
fprintf(stderr, "[TRACE ERROR]: pid %5d : readlink(%s) error : %m\n", pid, path_buf);
}

return 0;
Expand Down Expand Up @@ -140,7 +146,7 @@ int handle_execve(int pid, struct ptrace_syscall_info *info)
}
}

// Ouput command
// Output command
for (i = 0; i < node_count; i++)
{
if (node_count == 1 && i == 0) // Only one
Expand Down

0 comments on commit 250980a

Please sign in to comment.