From 8f17f6eb2db11cf8c93c47eda6eafc4981eeab29 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 24 Jan 2021 07:48:22 -0500 Subject: [PATCH 1/3] ospf6d: use a new json_object per loop iteration When redistributing multiple route types into ospfv3 the code must create a new array per route type into the the json code. Signed-off-by: Donald Sharp --- ospf6d/ospf6_asbr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index af99bc0c88..fdfd53276e 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1439,8 +1439,7 @@ static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6, struct ospf6_redist *red; total = 0; - for (type = 0; type < ZEBRA_ROUTE_MAX; type++) - nroute[type] = 0; + memset(nroute, 0, sizeof(nroute)); for (route = ospf6_route_head(ospf6->external_table); route; route = ospf6_route_next(route)) { info = route->route_option; @@ -1448,12 +1447,11 @@ static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6, total++; } - if (use_json) - json_route = json_object_new_object(); - else + if (!use_json) vty_out(vty, "Redistributing External Routes from:\n"); for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { + red = ospf6_redist_lookup(ospf6, type, 0); if (!red) @@ -1462,6 +1460,7 @@ static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6, continue; if (use_json) { + json_route = json_object_new_object(); json_object_string_add(json_route, "routeType", ZROUTE_NAME(type)); json_object_int_add(json_route, "numberOfRoutes", From 833c1f9fd14c4764b9f36f5e61c57130ff4f7118 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 24 Jan 2021 07:52:55 -0500 Subject: [PATCH 2/3] lib: Prevent possible memory overwrite fname is MAXPATHLEN and scriptdir and fs->name are less then MAXPATHLEN but the combination of those two + the `.lua` are greater than the MAXPATHLEN. Just give us more room to prevent a coding boo boo. Signed-off-by: Donald Sharp --- lib/frrscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/frrscript.c b/lib/frrscript.c index a3de474a4e..a43f389f99 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -208,7 +208,7 @@ struct frrscript *frrscript_load(const char *name, fs->L = luaL_newstate(); frrlua_export_logging(fs->L); - char fname[MAXPATHLEN]; + char fname[MAXPATHLEN * 2]; snprintf(fname, sizeof(fname), "%s/%s.lua", scriptdir, fs->name); int ret = luaL_loadfile(fs->L, fname); From ea6caa1f523a355cc95a1c73432e595f5ef4ec46 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 24 Jan 2021 08:00:43 -0500 Subject: [PATCH 3/3] lib: Wrapper a function to make gcc-10 happy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc-10 is complaining: lib/frrscript.c:42:14: error: cast between incompatible function types from ‘const char * (*)(lua_State *, const char *)’ to ‘void (*)(lua_State *, const void *)’ [-Werror=cast-function-type] 42 | .encoder = (encoder_func)lua_pushstring, | ^ Wrapper it to make it happy. Not sure what else to do. Signed-off-by: Donald Sharp --- lib/frrlua.h | 11 +++++++++++ lib/frrscript.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/frrlua.h b/lib/frrlua.h index 8e52931e50..6fb30938b0 100644 --- a/lib/frrlua.h +++ b/lib/frrlua.h @@ -34,6 +34,17 @@ extern "C" { #endif +/* + * gcc-10 is complaining about the wrapper function + * not being compatible with lua_pushstring returning + * a char *. Let's wrapper it here to make our life + * easier + */ +static inline void lua_pushstring_wrapper(lua_State *L, const char *str) +{ + (void)lua_pushstring(L, str); +} + /* * Converts a prefix to a Lua value and pushes it on the stack. */ diff --git a/lib/frrscript.c b/lib/frrscript.c index a43f389f99..10d400886d 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -39,7 +39,7 @@ struct frrscript_codec frrscript_codecs_lib[] = { .encoder = (encoder_func)lua_pushintegerp, .decoder = lua_tointegerp}, {.typename = "string", - .encoder = (encoder_func)lua_pushstring, + .encoder = (encoder_func)lua_pushstring_wrapper, .decoder = lua_tostringp}, {.typename = "prefix", .encoder = (encoder_func)lua_pushprefix,