lib: fix possible freeing of libyang data

mgmtd frees all non-NULL change->value variables at the end of every
commit. We shouldn't assign change->value with data returned by libyang
to prevent freeing of library-allocated memory.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit 814b9fb772)
This commit is contained in:
Igor Ryzhov 2023-11-11 02:06:11 +02:00 committed by Mergify
parent 3fba3d5d4f
commit c720f9cdb7

View File

@ -842,6 +842,7 @@ void nb_candidate_edit_config_changes(
struct nb_cfg_change *change = &cfg_changes[i];
struct nb_node *nb_node;
char xpath[XPATH_MAXLEN];
const char *value;
struct yang_data *data;
int ret;
@ -879,9 +880,10 @@ void nb_candidate_edit_config_changes(
}
/* If the value is not set, get the default if it exists. */
if (change->value == NULL)
change->value = yang_snode_get_default(nb_node->snode);
data = yang_data_new(xpath, change->value);
value = change->value;
if (value == NULL)
value = yang_snode_get_default(nb_node->snode);
data = yang_data_new(xpath, value);
/*
* Ignore "not found" errors when editing the candidate