From 2b442f69e22d1592a67490731a6e9d7443351476 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Oct 2020 21:44:29 -0400 Subject: [PATCH] sharpd: Fix nexthop group name collision If you have two nexthop groups named one oneone then the sharp daemon will treat them as the same nexthop group. This is because we are doign this: static int sharp_nhg_compare_func(const struct sharp_nhg *a, const struct sharp_nhg *b) { return strncmp(a->name, b->name, strlen(a->name)); } The strlen should be the size of the array of name. Signed-off-by: Donald Sharp --- sharpd/sharp_nht.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c index 7484dd3b06..077e2b29eb 100644 --- a/sharpd/sharp_nht.c +++ b/sharpd/sharp_nht.c @@ -77,7 +77,8 @@ struct sharp_nhg { uint32_t id; - char name[256]; +#define NHG_NAME_LEN 256 + char name[NHG_NAME_LEN]; bool installed; }; @@ -95,7 +96,7 @@ struct sharp_nhg_rb_head nhg_head; static int sharp_nhg_compare_func(const struct sharp_nhg *a, const struct sharp_nhg *b) { - return strncmp(a->name, b->name, strlen(a->name)); + return strncmp(a->name, b->name, NHG_NAME_LEN); } DECLARE_RBTREE_UNIQ(sharp_nhg_rb, struct sharp_nhg, mylistitem, -- 2.39.5