mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
vsh: Fix some issues in auto completion code
1. Move the declaration of const vshCmdDef *help - it should be at the top of the "if" rather than in the middle. 2. Change a comparison from && to || - without doing so we could crash on commands like 'virsh list' which would allow completion of some non -- option based on whatever was found in the current working directory and then as soon as that was completed, the next <tab> would crash since "opt" would be returned as NULL, but the check was dereferencing "&& opt->type" 3. Before dereferencing opt->completer, be sure opt isn't NULL.
This commit is contained in:
parent
6de78c63a4
commit
f6a4ccdc83
@ -1523,10 +1523,11 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
|
|||||||
/* if we encountered --help, replace parsed command with
|
/* if we encountered --help, replace parsed command with
|
||||||
* 'help <cmdname>' */
|
* 'help <cmdname>' */
|
||||||
for (tmpopt = first; tmpopt; tmpopt = tmpopt->next) {
|
for (tmpopt = first; tmpopt; tmpopt = tmpopt->next) {
|
||||||
|
const vshCmdDef *help;
|
||||||
if (STRNEQ(tmpopt->def->name, "help"))
|
if (STRNEQ(tmpopt->def->name, "help"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const vshCmdDef *help = vshCmddefSearch("help");
|
help = vshCmddefSearch("help");
|
||||||
vshCommandOptFree(first);
|
vshCommandOptFree(first);
|
||||||
first = vshMalloc(ctl, sizeof(vshCmdOpt));
|
first = vshMalloc(ctl, sizeof(vshCmdOpt));
|
||||||
first->def = help->opts;
|
first->def = help->opts;
|
||||||
@ -2788,7 +2789,7 @@ vshReadlineParse(const char *text, int state)
|
|||||||
* Try to find the default option.
|
* Try to find the default option.
|
||||||
*/
|
*/
|
||||||
if (!(opt = vshCmddefGetData(cmd, &opts_need_arg, &opts_seen))
|
if (!(opt = vshCmddefGetData(cmd, &opts_need_arg, &opts_seen))
|
||||||
&& opt->type == VSH_OT_BOOL)
|
|| opt->type == VSH_OT_BOOL)
|
||||||
goto error;
|
goto error;
|
||||||
opt_exists = true;
|
opt_exists = true;
|
||||||
opts_need_arg = const_opts_need_arg;
|
opts_need_arg = const_opts_need_arg;
|
||||||
@ -2824,7 +2825,7 @@ vshReadlineParse(const char *text, int state)
|
|||||||
res = vshReadlineCommandGenerator(sanitized_text, state);
|
res = vshReadlineCommandGenerator(sanitized_text, state);
|
||||||
} else if (opts_filled && !non_bool_opt_exists) {
|
} else if (opts_filled && !non_bool_opt_exists) {
|
||||||
res = vshReadlineOptionsGenerator(sanitized_text, state, cmd);
|
res = vshReadlineOptionsGenerator(sanitized_text, state, cmd);
|
||||||
} else if (non_bool_opt_exists && data_complete && opt->completer) {
|
} else if (non_bool_opt_exists && data_complete && opt && opt->completer) {
|
||||||
if (!completed_list)
|
if (!completed_list)
|
||||||
completed_list = opt->completer(autoCompleteOpaque,
|
completed_list = opt->completer(autoCompleteOpaque,
|
||||||
opt->completer_flags);
|
opt->completer_flags);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user