diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-03-31 11:05:31 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-03-31 11:11:28 +0200 |
| commit | 7422eeb846a69b924b8a71377fda1d4ca27370ce (patch) | |
| tree | 223d631f219320f83909992ebcb2e3754774e175 /vis.c | |
| parent | 5bb67f6738f0eb99558618412cd0b035538f77c5 (diff) | |
| download | vis-7422eeb846a69b924b8a71377fda1d4ca27370ce.tar.gz vis-7422eeb846a69b924b8a71377fda1d4ca27370ce.tar.xz | |
Do not modify the argument to exec_command
This fixes a segfault when using the ZQ key binding as reported
by Silvan Jegen.
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -543,7 +543,7 @@ static bool vis_window_split(EditorWin *win); static Key getkey(void); static void keypress(Key *key); static void action_do(Action *a); -static bool exec_command(char type, char *cmdline); +static bool exec_command(char type, const char *cmdline); /** operator implementations of type: void (*op)(OperatorContext*) */ @@ -1095,8 +1095,7 @@ static void quit(const Arg *arg) { } static void cmd(const Arg *arg) { - /* casting to char* is only save if arg->s contains no arguments */ - exec_command(':', (char*)arg->s); + exec_command(':', arg->s); } static int argi2lines(const Arg *arg) { @@ -1754,19 +1753,24 @@ static Filerange parse_range(char **cmd) { return r; } -static bool exec_cmdline_command(char *line) { +static bool exec_cmdline_command(const char *cmdline) { enum CmdOpt opt = CMD_OPT_NONE; + char *line = strdup(cmdline); char *name = line; + if (!line) + return false; Filerange range = parse_range(&name); if (!text_range_valid(&range)) { /* if only one position was given, jump to it */ if (range.start != EPOS && !*name) { window_cursor_to(vis->win->win, range.start); + free(line); return true; } if (name != line) { editor_info_show(vis, "Invalid range\n"); + free(line); return false; } range = (Filerange){ .start = 0, .end = text_size(vis->win->text) }; @@ -1788,6 +1792,7 @@ static bool exec_cmdline_command(char *line) { Command *cmd = map_closest(cmdmap, name); if (!cmd) { editor_info_show(vis, "Not an editor command"); + free(line); return false; } @@ -1817,10 +1822,11 @@ static bool exec_cmdline_command(char *line) { } cmd->cmd(&range, opt, argv); + free(line); return true; } -static bool exec_command(char type, char *cmd) { +static bool exec_command(char type, const char *cmd) { if (!cmd || !cmd[0]) return true; switch (type) { |
