? DEADJOE ? doc/quagga-single.html ? lib/DEADJOE ? lib/aaa-notes.txt ? vtysh/vtyd_main.c Index: lib/ChangeLog =================================================================== RCS file: /var/cvsroot/quagga/lib/ChangeLog,v retrieving revision 1.148 diff -u -w -b -p -r1.148 ChangeLog --- lib/ChangeLog 9 Mar 2005 13:42:23 -0000 1.148 +++ lib/ChangeLog 14 Mar 2005 17:00:02 -0000 @@ -1,3 +1,25 @@ +2005-03-14 Paul Jakma + + * command.c: (sort_node) use vector_max instead of referencing + (struct vector *)->max directly. Test that vector_max is > 0 + before using it to calculate an index. + Fixup vector loop to make main body conditional on vector slot + not being empty. + (cmd_cmdsize) Fixup vector loop to make main body conditional on + vector slot not being empty. + (cmd_filter_by_completion) ditto + (cmd_filter_by_string) ditto + (is_cmd_ambiguous) ditto + (cmd_describe_command_real) Change index integers to unsigned. + Test that vector_max is > 0 before using it to calculate an index. + Return immediately with CMD_ERR_NO_MATCH if vline has no + active slots. + Fixup vector loop to make main body conditional on vector slot + not being empty. + (cmd_complete_command_real) ditto. + (cmd_execute_command_strict) Fixup vector loop to be conditional + on non-null slot. + 2005-03-09 Paul Jakma * command.c: Undo commit of sign warning fix and hidden command Index: lib/command.c =================================================================== RCS file: /var/cvsroot/quagga/lib/command.c,v retrieving revision 1.43 diff -u -w -b -p -r1.43 command.c --- lib/command.c 9 Mar 2005 13:42:23 -0000 1.43 +++ lib/command.c 14 Mar 2005 17:00:04 -0000 @@ -220,14 +220,17 @@ sort_node () if ((cnode = vector_slot (cmdvec, i)) != NULL) { vector cmd_vector = cnode->cmd_vector; - qsort (cmd_vector->index, cmd_vector->max, sizeof (void *), cmp_node); + qsort (cmd_vector->index, vector_max (cmd_vector), + sizeof (void *), cmp_node); for (j = 0; j < vector_max (cmd_vector); j++) - if ((cmd_element = vector_slot (cmd_vector, j)) != NULL) + if ((cmd_element = vector_slot (cmd_vector, j)) != NULL + && vector_max (cmd_element->strvec)) { descvec = vector_slot (cmd_element->strvec, vector_max (cmd_element->strvec) - 1); - qsort (descvec->index, descvec->max, sizeof (void *), cmp_desc); + qsort (descvec->index, vector_max (descvec), + sizeof (void *), cmp_desc); } } } @@ -437,15 +440,14 @@ cmd_cmdsize (vector strvec) unsigned int i; int size = 0; vector descvec; + struct desc *desc; for (i = 0; i < vector_max (strvec); i++) + if ((descvec = vector_slot (strvec, i)) != NULL) { - descvec = vector_slot (strvec, i); - - if (vector_max (descvec) == 1) + if ((vector_max (descvec)) == 1 + && (desc = vector_slot (descvec, 0)) != NULL) { - struct desc *desc = vector_slot (descvec, 0); - if (desc->cmd == NULL || CMD_OPTION (desc->cmd)) return size; else @@ -1137,8 +1139,8 @@ cmd_filter_by_completion (char *command, descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) + if ((desc = vector_slot (descvec, j))) { - desc = vector_slot (descvec, j); str = desc->cmd; if (CMD_VARARG (str)) @@ -1254,8 +1256,8 @@ cmd_filter_by_string (char *command, vec descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) + if ((desc = vector_slot (descvec, j))) { - desc = vector_slot (descvec, j); str = desc->cmd; if (CMD_VARARG (str)) @@ -1353,10 +1355,10 @@ is_cmd_ambiguous (char *command, vector descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) + if ((desc = vector_slot (descvec, j))) { enum match_type ret; - desc = vector_slot (descvec, j); str = desc->cmd; switch (type) @@ -1561,18 +1563,24 @@ cmd_try_do_shortcut (enum node_type node static vector cmd_describe_command_real (vector vline, struct vty *vty, int *status) { - int i; + unsigned int i; vector cmd_vector; #define INIT_MATCHVEC_SIZE 10 vector matchvec; struct cmd_element *cmd_element; - int index; + unsigned int index; int ret; enum match_type match; char *command; static struct desc desc_cr = { "", "" }; /* Set index. */ + if (vector_max (vline) == 0) + { + *status = CMD_ERR_NO_MATCH; + return NULL; + } + else index = vector_max (vline) - 1; /* Make copy vector of current node's command vector. */ @@ -1584,8 +1592,8 @@ cmd_describe_command_real (vector vline, /* Filter commands. */ /* Only words precedes current word will be checked in this loop. */ for (i = 0; i < index; i++) + if ((command = vector_slot (vline, i))) { - command = vector_slot (vline, i); match = cmd_filter_by_completion (command, cmd_vector, i); if (match == vararg_match) @@ -1595,7 +1603,8 @@ cmd_describe_command_real (vector vline, unsigned int j, k; for (j = 0; j < vector_max (cmd_vector); j++) - if ((cmd_element = vector_slot (cmd_vector, j)) != NULL) + if ((cmd_element = vector_slot (cmd_vector, j)) != NULL + && (vector_max (cmd_element->strvec))) { descvec = vector_slot (cmd_element->strvec, vector_max (cmd_element->strvec) - 1); @@ -1660,8 +1669,8 @@ cmd_describe_command_real (vector vline, struct desc *desc; for (j = 0; j < vector_max (descvec); j++) + if ((desc = vector_slot (descvec, j))) { - desc = vector_slot (descvec, j); string = cmd_entry_function_desc (command, desc->cmd); if (string) { @@ -1757,26 +1766,33 @@ cmd_lcd (char **matched) static char ** cmd_complete_command_real (vector vline, struct vty *vty, int *status) { - int i; + unsigned int i; vector cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); #define INIT_MATCHVEC_SIZE 10 vector matchvec; struct cmd_element *cmd_element; - int index = vector_max (vline) - 1; + unsigned int index; char **match_str; struct desc *desc; vector descvec; char *command; int lcd; + if (vector_max (vline) == 0) + { + *status = CMD_ERR_NO_MATCH; + return NULL; + } + else + index = vector_max (vline) - 1; + /* First, filter by preceeding command string */ for (i = 0; i < index; i++) + if ((command = vector_slot (vline, i))) { enum match_type match; int ret; - command = vector_slot (vline, i); - /* First try completion match, if there is exactly match return 1 */ match = cmd_filter_by_completion (command, cmd_vector, i); @@ -1803,7 +1819,7 @@ cmd_complete_command_real (vector vline, /* Now we got into completion */ for (i = 0; i < vector_max (cmd_vector); i++) - if ((cmd_element = vector_slot (cmd_vector, i)) != NULL) + if ((cmd_element = vector_slot (cmd_vector, i))) { const char *string; vector strvec = cmd_element->strvec; @@ -1817,9 +1833,8 @@ cmd_complete_command_real (vector vline, descvec = vector_slot (strvec, index); for (j = 0; j < vector_max (descvec); j++) + if ((desc = vector_slot (descvec, j))) { - desc = vector_slot (descvec, j); - if ((string = cmd_entry_function (vector_slot (vline, index), desc->cmd))) if (cmd_unique_string (matchvec, string)) @@ -1981,11 +1996,10 @@ cmd_execute_command_real (vector vline, cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); for (index = 0; index < vector_max (vline); index++) + if ((command = vector_slot (vline, index))) { int ret; - command = vector_slot (vline, index); - match = cmd_filter_by_completion (command, cmd_vector, index); if (match == vararg_match) @@ -2011,10 +2025,8 @@ cmd_execute_command_real (vector vline, incomplete_count = 0; for (i = 0; i < vector_max (cmd_vector); i++) - if (vector_slot (cmd_vector,i) != NULL) + if ((cmd_element = vector_slot (cmd_vector,i))) { - cmd_element = vector_slot (cmd_vector,i); - if (match == vararg_match || index >= cmd_element->cmdsize) { matched_element = cmd_element; @@ -2164,11 +2176,10 @@ cmd_execute_command_strict (vector vline cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); for (index = 0; index < vector_max (vline); index++) + if ((command = vector_slot (vline, index))) { int ret; - command = vector_slot (vline, index); - match = cmd_filter_by_string (vector_slot (vline, index), cmd_vector, index);