summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c11
-rw-r--r--lib/frrstr.c10
-rw-r--r--lib/vector.c1
-rw-r--r--lib/vty.c1
4 files changed, 16 insertions, 7 deletions
diff --git a/lib/command.c b/lib/command.c
index c04360f28..ad0479dc9 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -285,7 +285,7 @@ vector cmd_make_strvec(const char *string)
if (*copy == '\0' || *copy == '!' || *copy == '#')
return NULL;
- vector result = frrstr_split_vec(copy, " \n\r\t");
+ vector result = frrstr_split_vec(copy, "\n\r\t ");
for (unsigned int i = 0; i < vector_active(result); i++) {
if (strlen(vector_slot(result, i)) == 0) {
@@ -1163,15 +1163,15 @@ int cmd_execute_command_strict(vector vline, struct vty *vty,
* The result of any processing.
*/
DECLARE_HOOK(cmd_execute,
- (struct vty * vty, const char *cmd_in, char **cmd_out),
+ (struct vty *vty, const char *cmd_in, char **cmd_out),
(vty, cmd_in, cmd_out));
-DEFINE_HOOK(cmd_execute, (struct vty * vty, const char *cmd_in, char **cmd_out),
+DEFINE_HOOK(cmd_execute, (struct vty *vty, const char *cmd_in, char **cmd_out),
(vty, cmd_in, cmd_out));
/* Hook executed after a CLI command. */
-DECLARE_KOOH(cmd_execute_done, (struct vty * vty, const char *cmd_exec),
+DECLARE_KOOH(cmd_execute_done, (struct vty *vty, const char *cmd_exec),
(vty, cmd_exec));
-DEFINE_KOOH(cmd_execute_done, (struct vty * vty, const char *cmd_exec),
+DEFINE_KOOH(cmd_execute_done, (struct vty *vty, const char *cmd_exec),
(vty, cmd_exec));
/*
@@ -1198,6 +1198,7 @@ static int handle_pipe_action(struct vty *vty, const char *cmd_in,
/* the remaining text should be a regexp */
char *regexp = working;
bool succ = vty_set_include(vty, regexp);
+
if (!succ) {
vty_out(vty, "%% Bad regexp '%s'", regexp);
goto fail;
diff --git a/lib/frrstr.c b/lib/frrstr.c
index b527827b3..03368b366 100644
--- a/lib/frrstr.c
+++ b/lib/frrstr.c
@@ -40,6 +40,7 @@ void frrstr_split(const char *string, const char *delimiter, char ***result,
*argc = 0;
const char *tok = NULL;
+
while (copy) {
tok = strsep(&copy, delimiter);
(*result)[idx] = XSTRDUP(MTYPE_TMP, tok);
@@ -50,8 +51,6 @@ void frrstr_split(const char *string, const char *delimiter, char ***result,
}
XFREE(MTYPE_TMP, copystart);
-
- return;
}
vector frrstr_split_vec(const char *string, const char *delimiter)
@@ -62,7 +61,9 @@ vector frrstr_split_vec(const char *string, const char *delimiter)
frrstr_split(string, delimiter, &result, &argc);
vector v = array_to_vector((void **)result, argc);
+
XFREE(MTYPE_TMP, result);
+
return v;
}
@@ -85,6 +86,7 @@ char *frrstr_join(const char **parts, int argc, const char *join)
for (i = 0; i < argc; i++) {
size_t arglen = strlen(parts[i]);
+
memcpy(p, parts[i], arglen);
p += arglen;
if (i + 1 != argc) {
@@ -115,6 +117,7 @@ char *frrstr_join_vec(vector v, const char *join)
void frrstr_filter_vec(vector v, regex_t *filter)
{
regmatch_t ignored[1];
+
for (unsigned int i = 0; i < vector_active(v); i++) {
if (regexec(filter, vector_slot(v, i), 0, ignored, 0)) {
XFREE(MTYPE_TMP, vector_slot(v, i));
@@ -143,9 +146,12 @@ bool begins_with(const char *str, const char *prefix)
{
if (!str || !prefix)
return 0;
+
size_t lenstr = strlen(str);
size_t lenprefix = strlen(prefix);
+
if (lenprefix > lenstr)
return 0;
+
return strncmp(str, prefix, lenprefix) == 0;
}
diff --git a/lib/vector.c b/lib/vector.c
index 75f6c00bd..ebac2b46e 100644
--- a/lib/vector.c
+++ b/lib/vector.c
@@ -192,6 +192,7 @@ void vector_to_array(vector v, void ***dest, int *argc)
vector array_to_vector(void **src, int argc)
{
vector v = vector_init(VECTOR_MIN_SIZE);
+
for (int i = 0; i < argc; i++)
vector_set_index(v, i, src[i]);
return v;
diff --git a/lib/vty.c b/lib/vty.c
index e4315e2d1..0bdcbf228 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -186,6 +186,7 @@ int vty_out(struct vty *vty, const char *format, ...)
/* filter buffer */
if (vty->filter) {
vector lines = frrstr_split_vec(buf, "\n");
+
frrstr_filter_vec(lines, &vty->include);
if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0)
vector_set(lines, XSTRDUP(MTYPE_TMP, ""));