Skip to content

Commit

Permalink
sheet: Fix bad memory access by duplicating filename string
Browse files Browse the repository at this point in the history
UI buffer frees this on closing and the indexing thread will use it so
it can't point to a stack variable or memory that gets overwritten
after the file is opened.
  • Loading branch information
richiejp committed Dec 9, 2024
1 parent 1eca52e commit ee8efe5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/sheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ static zsvsheet_status zsvsheet_open_file_handler(struct zsvsheet_proc_context *
UNUSED(ctx);

if (ctx->num_params > 0) {
filename = ctx->params[0].u.string;
filename = strdup(ctx->params[0].u.string);
} else {
if (!ctx->invocation.interactive)
return zsvsheet_status_error;
get_subcommand("File to open", prompt_buffer, sizeof(prompt_buffer), prompt_footer_row);
if (*prompt_buffer == '\0')
goto no_input;
filename = prompt_buffer;
filename = strdup(prompt_buffer);
}

if ((err = zsvsheet_ui_buffer_open_file(filename, NULL, state->custom_prop_handler, di->ui_buffers.base,
Expand Down

0 comments on commit ee8efe5

Please sign in to comment.