Skip to content
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

Grow the path buffer when reading /proc/.../maps #396

Merged
merged 2 commits into from
Dec 2, 2024
Merged
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
19 changes: 16 additions & 3 deletions reprozip/native/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ int trace_add_files_from_proc(unsigned int process, pid_t tid,
char dummy;
char *line = NULL;
size_t length = 0;
char previous_path[4096] = "";
size_t previous_path_size = 4096;
char *previous_path = malloc(previous_path_size);
remram44 marked this conversation as resolved.
Show resolved Hide resolved
previous_path[0] = 0;

const char *const fmt = "/proc/%d/maps";
int len = snprintf(&dummy, 1, fmt, tid);
Expand Down Expand Up @@ -301,19 +303,30 @@ int trace_add_files_from_proc(unsigned int process, pid_t tid,
if(inode > 0)
{
if(strcmp(pathname, binary) != 0
&& strncmp(pathname, previous_path, 4096) != 0)
&& strcmp(pathname, previous_path) != 0)
{
#ifdef DEBUG_PROC_PARSER
log_info(tid, " adding to database");
#endif
if(db_add_file_open(process, pathname,
FILE_READ, path_is_dir(pathname)) != 0)
return -1;
strncpy(previous_path, pathname, 4096);
{
size_t needed_size = strlen(pathname) + 1;
if(needed_size > previous_path_size) {
while(needed_size > previous_path_size) {
previous_path_size *= 2;
}
free(previous_path);
previous_path = malloc(previous_path_size);
}
}
strcpy(previous_path, pathname);
}
}
}
fclose(fp);
free(previous_path);
return 0;
}

Expand Down