Skip to content

Commit 29254fa

Browse files
committed
client BUGFIX double free
memory corruption when processing generic RPC created by nc_rpc_act_generic()
1 parent e639b15 commit 29254fa

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/session_client.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ API NC_MSG_TYPE
17921792
nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_t *msgid)
17931793
{
17941794
NC_MSG_TYPE r;
1795-
int ret;
1795+
int ret, dofree = 1;
17961796
struct nc_rpc_act_generic *rpc_gen;
17971797
struct nc_rpc_getconfig *rpc_gc;
17981798
struct nc_rpc_edit *rpc_e;
@@ -1839,6 +1839,7 @@ nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_
18391839

18401840
if (rpc_gen->has_data) {
18411841
data = rpc_gen->content.data;
1842+
dofree = 0;
18421843
} else {
18431844
data = lyd_parse_mem(session->ctx, rpc_gen->content.xml_str, LYD_XML, LYD_OPT_RPC | LYD_OPT_NOEXTDEPS
18441845
| (session->flags & NC_SESSION_CLIENT_NOT_STRICT ? 0 : LYD_OPT_STRICT), NULL);
@@ -2267,7 +2268,9 @@ nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_
22672268

22682269
if (lyd_validate(&data, LYD_OPT_RPC | LYD_OPT_NOEXTDEPS
22692270
| (session->flags & NC_SESSION_CLIENT_NOT_STRICT ? 0 : LYD_OPT_STRICT), NULL)) {
2270-
lyd_free(data);
2271+
if (dofree) {
2272+
lyd_free(data);
2273+
}
22712274
return NC_MSG_ERROR;
22722275
}
22732276

@@ -2285,7 +2288,9 @@ nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_
22852288
}
22862289
nc_session_unlock(session, timeout, __func__);
22872290

2288-
lyd_free(data);
2291+
if (dofree) {
2292+
lyd_free(data);
2293+
}
22892294

22902295
if (r != NC_MSG_RPC) {
22912296
return r;

0 commit comments

Comments
 (0)