diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-31 03:34:27 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-31 03:34:27 +0000 |
| commit | 5b5231b091e69da604d1f28303dcc2cc3fc02976 (patch) | |
| tree | cef568d8042360c926911d563ed9b6b9882499d5 /lib/command.c | |
| parent | e3e6107d9a159fa61c01274b7925e8e9ed580094 (diff) | |
lib: Fix segfault on erroneous command
Command completion vector should only be copied if it is
non-null.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/command.c b/lib/command.c index a12591a8bc..5e493a1c01 100644 --- a/lib/command.c +++ b/lib/command.c @@ -677,20 +677,21 @@ cmd_complete_command (vector vline, struct vty *vty, int *status) vector comps, initial_comps; initial_comps = cmd_complete_command_real (input_line, vty, status); - // filter out everything that is not suitable for a tab-completion - comps = vector_init (VECTOR_MIN_SIZE); - for (unsigned int i = 0; i < vector_active(initial_comps); i++) - { - struct cmd_token *token = vector_slot (initial_comps, i); - if (token->type == WORD_TKN) - vector_set (comps, token); - else - del_cmd_token (token); - } - vector_free (initial_comps); - if (!MATCHER_ERROR (*status)) { + assert (initial_comps); + // filter out everything that is not suitable for a tab-completion + comps = vector_init (VECTOR_MIN_SIZE); + for (unsigned int i = 0; i < vector_active(initial_comps); i++) + { + struct cmd_token *token = vector_slot (initial_comps, i); + if (token->type == WORD_TKN) + vector_set (comps, token); + else + del_cmd_token (token); + } + vector_free (initial_comps); + // copy completions text into an array of char* ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1); unsigned int i; |
