From 51d41d759bcd02506ec562018faace777dcee352 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Sun, 2 Oct 2016 03:27:58 +0000 Subject: [PATCH] lib: Null-terminate tab completions char*[] vtysh expects the result of a tab completion to have a null pointer as the last element Signed-off-by: Quentin Young --- lib/command.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/command.c b/lib/command.c index 9d68f33989..405cf6de66 100644 --- a/lib/command.c +++ b/lib/command.c @@ -618,8 +618,9 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) // get token completions vector comps = cmd_complete_command_real (shifted_vline, vty, status); - ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *)); - for (unsigned int i = 0; i < vector_active (comps); i++) + ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1); + unsigned int i; + for (i = 0; i < vector_active (comps); i++) { struct cmd_token *token = vector_slot (comps, i); ret[i] = XSTRDUP (MTYPE_TMP, token->text); @@ -627,6 +628,7 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) del_cmd_token (token); } vector_free (comps); + ret[i] = NULL; vector_free(shifted_vline); vty->node = onode; @@ -635,14 +637,16 @@ cmd_complete_command_lib (vector vline, struct vty *vty, int *status, int islib) // get token completions vector comps = cmd_complete_command_real (vline, vty, status); - ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *)); - for (unsigned int i = 0; i < vector_active (comps); i++) + ret = XMALLOC (MTYPE_TMP, vector_active (comps) * sizeof (char *) + 1); + unsigned int i; + for (i = 0; i < vector_active (comps); i++) { struct cmd_token *token = vector_slot (comps, i); ret[i] = XSTRDUP (MTYPE_TMP, token->text); vector_unset (comps, i); del_cmd_token (token); } + ret[i] = NULL; vector_free (comps); return ret; -- 2.39.5