mirror of
https://github.com/crash-utility/crash
synced 2025-02-23 00:46:48 +00:00
Fix for the "arguments-input-file" feature to protect against a
called command modifying an argument string. For example, the "struct" command modifies "-l struct_name.member" argument strings, and so without the patch, all iterative calls after the first one will fail. (anderson@redhat.com)
This commit is contained in:
parent
81d7896441
commit
0ead5809b9
15
cmdline.c
15
cmdline.c
@ -2437,6 +2437,8 @@ exec_args_input_file(struct command_table_entry *ct, struct args_input_file *aif
|
||||
char *new_args[MAXARGS];
|
||||
char *orig_args[MAXARGS];
|
||||
char orig_line[BUFSIZE];
|
||||
char *save_args[MAXARGS];
|
||||
char save_line[BUFSIZE];
|
||||
|
||||
if ((pc->args_ifile = fopen(aif->fileptr, "r")) == NULL)
|
||||
error(FATAL, "%s: %s\n", aif->fileptr, strerror(errno));
|
||||
@ -2447,11 +2449,24 @@ exec_args_input_file(struct command_table_entry *ct, struct args_input_file *aif
|
||||
BCOPY(args, orig_args, sizeof(args));
|
||||
orig_argcnt = argcnt;
|
||||
|
||||
/*
|
||||
* Commands cannot be trusted to leave the arguments intact.
|
||||
* Stash them here and restore them each time through the loop.
|
||||
*/
|
||||
save_args[0] = save_line;
|
||||
for (i = 0; i < orig_argcnt; i++) {
|
||||
strcpy(save_args[i], orig_args[i]);
|
||||
save_args[i+1] = save_args[i] + strlen(save_args[i]) + 2;
|
||||
}
|
||||
|
||||
while (fgets(buf, BUFSIZE-1, pc->args_ifile)) {
|
||||
clean_line(buf);
|
||||
if ((strlen(buf) == 0) || (buf[0] == '#'))
|
||||
continue;
|
||||
|
||||
for (i = 1; i < orig_argcnt; i++)
|
||||
strcpy(orig_args[i], save_args[i]);
|
||||
|
||||
if (aif->is_gdb_cmd) {
|
||||
console("(gdb) before: [%s]\n", orig_line);
|
||||
strcpy(pc->orig_line, orig_line);
|
||||
|
Loading…
Reference in New Issue
Block a user