From e9b8ccb48f4f3d6595db65f23c15b78503958b0c Mon Sep 17 00:00:00 2001 From: Yash Ranjan Date: Tue, 17 Aug 2021 22:24:17 -0700 Subject: [PATCH] cmgd: fix crash for get-data with certain xpaths Xpaths with trailing slash '/' crashes at yang_done get. Signed-off-by: Yash Ranjan --- cmgd/cmgd_db.c | 3 +++ cmgd/cmgd_db.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cmgd/cmgd_db.c b/cmgd/cmgd_db.c index e99e0be79c5d..8e35f5e4e093 100644 --- a/cmgd/cmgd_db.c +++ b/cmgd/cmgd_db.c @@ -385,6 +385,7 @@ int cmgd_db_lookup_data_nodes( xpath += 2; strncpy(base_xpath, xpath, sizeof(base_xpath)); + remove_slash_at_the_end(base_xpath); return (cmgd_walk_db_nodes(db_ctxt, base_xpath, NULL, NULL, NULL, dxpaths, dnodes, nbnodes, num_nodes, @@ -456,6 +457,8 @@ int cmgd_db_iter_data( if (!db_ctxt) return -1; + remove_slash_at_the_end(base_xpath); + strncpy(xpath, base_xpath, sizeof(xpath)); CMGD_DB_DBG(" -- START DB walk for DBid: %d", db_ctxt->db_id); diff --git a/cmgd/cmgd_db.h b/cmgd/cmgd_db.h index d972ce9ecd12..1473a3603c00 100644 --- a/cmgd/cmgd_db.h +++ b/cmgd/cmgd_db.h @@ -41,6 +41,9 @@ #define FOREACH_CMGD_DB_ID(id) \ for ((id) = CMGD_DB_NONE; (id) < CMGD_DB_MAX_ID; (id)++) +#define remove_slash_at_the_end(str) \ + if (str[strlen(str) - 1] == '/') str[strlen(str) - 1] = '\0' + typedef uintptr_t cmgd_db_hndl_t; typedef void (*cmgd_db_node_iter_fn)(cmgd_db_hndl_t db_hndl,