? 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 -p -r1.148 ChangeLog --- lib/ChangeLog 9 Mar 2005 13:42:23 -0000 1.148 +++ lib/ChangeLog 14 Mar 2005 16:59:41 -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 -p -r1.43 command.c --- lib/command.c 9 Mar 2005 13:42:23 -0000 1.43 +++ lib/command.c 14 Mar 2005 16:59:43 -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,87 +1139,87 @@ cmd_filter_by_completion (char *command, descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - str = desc->cmd; - - if (CMD_VARARG (str)) - { - if (match_type < vararg_match) - match_type = vararg_match; - matched++; - } - else if (CMD_RANGE (str)) - { - if (cmd_range_match (str, command)) - { - if (match_type < range_match) - match_type = range_match; - - matched++; - } - } + if ((desc = vector_slot (descvec, j))) + { + str = desc->cmd; + + if (CMD_VARARG (str)) + { + if (match_type < vararg_match) + match_type = vararg_match; + matched++; + } + else if (CMD_RANGE (str)) + { + if (cmd_range_match (str, command)) + { + if (match_type < range_match) + match_type = range_match; + + matched++; + } + } #ifdef HAVE_IPV6 - else if (CMD_IPV6 (str)) - { - if (cmd_ipv6_match (command)) - { - if (match_type < ipv6_match) - match_type = ipv6_match; - - matched++; - } - } - else if (CMD_IPV6_PREFIX (str)) - { - if (cmd_ipv6_prefix_match (command)) - { - if (match_type < ipv6_prefix_match) - match_type = ipv6_prefix_match; - - matched++; - } - } + else if (CMD_IPV6 (str)) + { + if (cmd_ipv6_match (command)) + { + if (match_type < ipv6_match) + match_type = ipv6_match; + + matched++; + } + } + else if (CMD_IPV6_PREFIX (str)) + { + if (cmd_ipv6_prefix_match (command)) + { + if (match_type < ipv6_prefix_match) + match_type = ipv6_prefix_match; + + matched++; + } + } #endif /* HAVE_IPV6 */ - else if (CMD_IPV4 (str)) - { - if (cmd_ipv4_match (command)) - { - if (match_type < ipv4_match) - match_type = ipv4_match; - - matched++; - } - } - else if (CMD_IPV4_PREFIX (str)) - { - if (cmd_ipv4_prefix_match (command)) - { - if (match_type < ipv4_prefix_match) - match_type = ipv4_prefix_match; - matched++; - } - } - else - /* Check is this point's argument optional ? */ - if (CMD_OPTION (str) || CMD_VARIABLE (str)) - { - if (match_type < extend_match) - match_type = extend_match; - matched++; - } - else if (strncmp (command, str, strlen (command)) == 0) - { - if (strcmp (command, str) == 0) - match_type = exact_match; - else - { - if (match_type < partly_match) - match_type = partly_match; - } - matched++; - } - } + else if (CMD_IPV4 (str)) + { + if (cmd_ipv4_match (command)) + { + if (match_type < ipv4_match) + match_type = ipv4_match; + + matched++; + } + } + else if (CMD_IPV4_PREFIX (str)) + { + if (cmd_ipv4_prefix_match (command)) + { + if (match_type < ipv4_prefix_match) + match_type = ipv4_prefix_match; + matched++; + } + } + else + /* Check is this point's argument optional ? */ + if (CMD_OPTION (str) || CMD_VARIABLE (str)) + { + if (match_type < extend_match) + match_type = extend_match; + matched++; + } + else if (strncmp (command, str, strlen (command)) == 0) + { + if (strcmp (command, str) == 0) + match_type = exact_match; + else + { + if (match_type < partly_match) + match_type = partly_match; + } + matched++; + } + } if (! matched) vector_slot (v, i) = NULL; } @@ -1254,78 +1256,78 @@ cmd_filter_by_string (char *command, vec descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - str = desc->cmd; - - if (CMD_VARARG (str)) - { - if (match_type < vararg_match) - match_type = vararg_match; - matched++; - } - else if (CMD_RANGE (str)) - { - if (cmd_range_match (str, command)) - { - if (match_type < range_match) - match_type = range_match; - matched++; - } - } + if ((desc = vector_slot (descvec, j))) + { + str = desc->cmd; + + if (CMD_VARARG (str)) + { + if (match_type < vararg_match) + match_type = vararg_match; + matched++; + } + else if (CMD_RANGE (str)) + { + if (cmd_range_match (str, command)) + { + if (match_type < range_match) + match_type = range_match; + matched++; + } + } #ifdef HAVE_IPV6 - else if (CMD_IPV6 (str)) - { - if (cmd_ipv6_match (command) == exact_match) - { - if (match_type < ipv6_match) - match_type = ipv6_match; - matched++; - } - } - else if (CMD_IPV6_PREFIX (str)) - { - if (cmd_ipv6_prefix_match (command) == exact_match) - { - if (match_type < ipv6_prefix_match) - match_type = ipv6_prefix_match; - matched++; - } - } + else if (CMD_IPV6 (str)) + { + if (cmd_ipv6_match (command) == exact_match) + { + if (match_type < ipv6_match) + match_type = ipv6_match; + matched++; + } + } + else if (CMD_IPV6_PREFIX (str)) + { + if (cmd_ipv6_prefix_match (command) == exact_match) + { + if (match_type < ipv6_prefix_match) + match_type = ipv6_prefix_match; + matched++; + } + } #endif /* HAVE_IPV6 */ - else if (CMD_IPV4 (str)) - { - if (cmd_ipv4_match (command) == exact_match) - { - if (match_type < ipv4_match) - match_type = ipv4_match; - matched++; - } - } - else if (CMD_IPV4_PREFIX (str)) - { - if (cmd_ipv4_prefix_match (command) == exact_match) - { - if (match_type < ipv4_prefix_match) - match_type = ipv4_prefix_match; - matched++; - } - } - else if (CMD_OPTION (str) || CMD_VARIABLE (str)) - { - if (match_type < extend_match) - match_type = extend_match; - matched++; - } - else - { - if (strcmp (command, str) == 0) - { - match_type = exact_match; - matched++; - } - } - } + else if (CMD_IPV4 (str)) + { + if (cmd_ipv4_match (command) == exact_match) + { + if (match_type < ipv4_match) + match_type = ipv4_match; + matched++; + } + } + else if (CMD_IPV4_PREFIX (str)) + { + if (cmd_ipv4_prefix_match (command) == exact_match) + { + if (match_type < ipv4_prefix_match) + match_type = ipv4_prefix_match; + matched++; + } + } + else if (CMD_OPTION (str) || CMD_VARIABLE (str)) + { + if (match_type < extend_match) + match_type = extend_match; + matched++; + } + else + { + if (strcmp (command, str) == 0) + { + match_type = exact_match; + matched++; + } + } + } if (! matched) vector_slot (v, i) = NULL; } @@ -1353,77 +1355,77 @@ is_cmd_ambiguous (char *command, vector descvec = vector_slot (cmd_element->strvec, index); for (j = 0; j < vector_max (descvec); j++) - { - enum match_type ret; - - desc = vector_slot (descvec, j); - str = desc->cmd; - - switch (type) - { - case exact_match: - if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) - && strcmp (command, str) == 0) - match++; - break; - case partly_match: - if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) - && strncmp (command, str, strlen (command)) == 0) - { - if (matched && strcmp (matched, str) != 0) - return 1; /* There is ambiguous match. */ - else - matched = str; - match++; - } - break; - case range_match: - if (cmd_range_match (str, command)) - { - if (matched && strcmp (matched, str) != 0) - return 1; - else - matched = str; - match++; - } - break; + if ((desc = vector_slot (descvec, j))) + { + enum match_type ret; + + str = desc->cmd; + + switch (type) + { + case exact_match: + if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) + && strcmp (command, str) == 0) + match++; + break; + case partly_match: + if (! (CMD_OPTION (str) || CMD_VARIABLE (str)) + && strncmp (command, str, strlen (command)) == 0) + { + if (matched && strcmp (matched, str) != 0) + return 1; /* There is ambiguous match. */ + else + matched = str; + match++; + } + break; + case range_match: + if (cmd_range_match (str, command)) + { + if (matched && strcmp (matched, str) != 0) + return 1; + else + matched = str; + match++; + } + break; #ifdef HAVE_IPV6 - case ipv6_match: - if (CMD_IPV6 (str)) - match++; - break; - case ipv6_prefix_match: - if ((ret = cmd_ipv6_prefix_match (command)) != no_match) - { - if (ret == partly_match) - return 2; /* There is incomplete match. */ - - match++; - } - break; + case ipv6_match: + if (CMD_IPV6 (str)) + match++; + break; + case ipv6_prefix_match: + if ((ret = cmd_ipv6_prefix_match (command)) != no_match) + { + if (ret == partly_match) + return 2; /* There is incomplete match. */ + + match++; + } + break; #endif /* HAVE_IPV6 */ - case ipv4_match: - if (CMD_IPV4 (str)) - match++; - break; - case ipv4_prefix_match: - if ((ret = cmd_ipv4_prefix_match (command)) != no_match) - { - if (ret == partly_match) - return 2; /* There is incomplete match. */ - - match++; - } - break; - case extend_match: - if (CMD_OPTION (str) || CMD_VARIABLE (str)) - match++; - break; - case no_match: - default: - break; - } - } + case ipv4_match: + if (CMD_IPV4 (str)) + match++; + break; + case ipv4_prefix_match: + if ((ret = cmd_ipv4_prefix_match (command)) != no_match) + { + if (ret == partly_match) + return 2; /* There is incomplete match. */ + + match++; + } + break; + case extend_match: + if (CMD_OPTION (str) || CMD_VARIABLE (str)) + match++; + break; + case no_match: + default: + break; + } + } if (! match) vector_slot (v, i) = NULL; } @@ -1561,19 +1563,25 @@ 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. */ - index = vector_max (vline) - 1; + 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. */ cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); @@ -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,16 +1669,16 @@ cmd_describe_command_real (vector vline, struct desc *desc; for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - string = cmd_entry_function_desc (command, desc->cmd); - if (string) - { - /* Uniqueness check */ - if (! desc_unique_string (matchvec, string)) - vector_set (matchvec, desc); - } - } + if ((desc = vector_slot (descvec, j))) + { + string = cmd_entry_function_desc (command, desc->cmd); + if (string) + { + /* Uniqueness check */ + if (! desc_unique_string (matchvec, string)) + vector_set (matchvec, desc); + } + } } } } @@ -1757,53 +1766,60 @@ 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++) - { - enum match_type match; - int ret; - - command = vector_slot (vline, i); + if ((command = vector_slot (vline, i))) + { + enum match_type match; + int ret; - /* First try completion match, if there is exactly match return 1 */ - match = cmd_filter_by_completion (command, cmd_vector, i); + /* First try completion match, if there is exactly match return 1 */ + match = cmd_filter_by_completion (command, cmd_vector, i); - /* If there is exact match then filter ambiguous match else check - ambiguousness. */ - if ((ret = is_cmd_ambiguous (command, cmd_vector, i, match)) == 1) - { - vector_free (cmd_vector); - *status = CMD_ERR_AMBIGUOUS; - return NULL; - } - /* - else if (ret == 2) - { - vector_free (cmd_vector); - *status = CMD_ERR_NO_MATCH; - return NULL; - } - */ - } + /* If there is exact match then filter ambiguous match else check + ambiguousness. */ + if ((ret = is_cmd_ambiguous (command, cmd_vector, i, match)) == 1) + { + vector_free (cmd_vector); + *status = CMD_ERR_AMBIGUOUS; + return NULL; + } + /* + else if (ret == 2) + { + vector_free (cmd_vector); + *status = CMD_ERR_NO_MATCH; + return NULL; + } + */ + } /* Prepare match vector. */ matchvec = vector_init (INIT_MATCHVEC_SIZE); /* 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,14 +1833,13 @@ cmd_complete_command_real (vector vline, descvec = vector_slot (strvec, index); for (j = 0; j < vector_max (descvec); j++) - { - desc = vector_slot (descvec, j); - - if ((string = cmd_entry_function (vector_slot (vline, index), - desc->cmd))) - if (cmd_unique_string (matchvec, string)) - vector_set (matchvec, XSTRDUP (MTYPE_TMP, string)); - } + if ((desc = vector_slot (descvec, j))) + { + if ((string = cmd_entry_function (vector_slot (vline, index), + desc->cmd))) + if (cmd_unique_string (matchvec, string)) + vector_set (matchvec, XSTRDUP (MTYPE_TMP, string)); + } } } @@ -1981,29 +1996,28 @@ cmd_execute_command_real (vector vline, cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); for (index = 0; index < vector_max (vline); index++) - { - int ret; - - command = vector_slot (vline, index); + if ((command = vector_slot (vline, index))) + { + int ret; - match = cmd_filter_by_completion (command, cmd_vector, index); + match = cmd_filter_by_completion (command, cmd_vector, index); - if (match == vararg_match) - break; + if (match == vararg_match) + break; - ret = is_cmd_ambiguous (command, cmd_vector, index, match); + ret = is_cmd_ambiguous (command, cmd_vector, index, match); - if (ret == 1) - { - vector_free (cmd_vector); - return CMD_ERR_AMBIGUOUS; - } - else if (ret == 2) - { - vector_free (cmd_vector); - return CMD_ERR_NO_MATCH; - } - } + if (ret == 1) + { + vector_free (cmd_vector); + return CMD_ERR_AMBIGUOUS; + } + else if (ret == 2) + { + vector_free (cmd_vector); + return CMD_ERR_NO_MATCH; + } + } /* Check matched count. */ matched_element = NULL; @@ -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,30 +2176,29 @@ cmd_execute_command_strict (vector vline cmd_vector = vector_copy (cmd_node_vector (cmdvec, vty->node)); for (index = 0; index < vector_max (vline); index++) - { - int ret; - - command = vector_slot (vline, index); - - match = cmd_filter_by_string (vector_slot (vline, index), - cmd_vector, index); + if ((command = vector_slot (vline, index))) + { + int ret; - /* If command meets '.VARARG' then finish matching. */ - if (match == vararg_match) - break; + match = cmd_filter_by_string (vector_slot (vline, index), + cmd_vector, index); - ret = is_cmd_ambiguous (command, cmd_vector, index, match); - if (ret == 1) - { - vector_free (cmd_vector); - return CMD_ERR_AMBIGUOUS; - } - if (ret == 2) - { - vector_free (cmd_vector); - return CMD_ERR_NO_MATCH; - } - } + /* If command meets '.VARARG' then finish matching. */ + if (match == vararg_match) + break; + + ret = is_cmd_ambiguous (command, cmd_vector, index, match); + if (ret == 1) + { + vector_free (cmd_vector); + return CMD_ERR_AMBIGUOUS; + } + if (ret == 2) + { + vector_free (cmd_vector); + return CMD_ERR_NO_MATCH; + } + } /* Check matched count. */ matched_element = NULL;