Skip to content

Commit

Permalink
lib: fix possible freeing of libyang data
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 814b9fb)
  • Loading branch information
idryzhov authored and mergify[bot] committed Nov 14, 2023
1 parent 3fba3d5 commit c720f9c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c720f9c

Please sign in to comment.