Skip to content

Commit 2c4d9de

Browse files
committed
session_client: fix segfault on NC_MSG_REPLY_ERR_MSGID
When retrieve_schema_data_getschema or build_schema_info_yl receive an NC_MSG_REPLY_ERR_MSGID error, they do not call nc_recv_reply again to receive the expected message. However, when msg == NC_MSG_REPLY_ERR_MSGID, reply is necessarily NULL, which causes a segfault when accessing the reply->type field. Call nc_recv_reply again if we receive an NC_MSG_REPLY_ERR_MSGID error. Also, nc_recv_reply may leave reply NULL for other reasons (NC_MSG_ERROR is not the only case). Return an error if reply is NULL to avoid potential further segfaults. Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
1 parent 373a40a commit 2c4d9de

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/session_client.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ retrieve_schema_data_getschema(const char *name, const char *rev, struct clb_dat
379379

380380
do {
381381
msg = nc_recv_reply(clb_data->session, rpc, msgid, NC_READ_ACT_TIMEOUT * 1000, 0, &reply);
382-
} while (msg == NC_MSG_NOTIF);
382+
} while (msg == NC_MSG_NOTIF || msg == NC_MSG_REPLY_ERR_MSGID);
383383
nc_rpc_free(rpc);
384384
if (msg == NC_MSG_WOULDBLOCK) {
385385
ERR("Session %u: timeout for receiving reply to a <get-schema> expired.", clb_data->session->id);
386386
return NULL;
387-
} else if (msg == NC_MSG_ERROR) {
387+
} else if (msg == NC_MSG_ERROR || reply == NULL) {
388388
ERR("Session %u: failed to receive a reply to <get-schema>.", clb_data->session->id);
389389
return NULL;
390390
}
@@ -710,11 +710,11 @@ build_schema_info_yl(struct nc_session *session, struct schema_info **result)
710710

711711
do {
712712
msg = nc_recv_reply(session, rpc, msgid, NC_READ_ACT_TIMEOUT * 1000, 0, &reply);
713-
} while (msg == NC_MSG_NOTIF);
713+
} while (msg == NC_MSG_NOTIF || msg == NC_MSG_REPLY_ERR_MSGID);
714714
if (msg == NC_MSG_WOULDBLOCK) {
715715
WRN("Session %u: timeout for receiving reply to a <get> yang-library data expired.", session->id);
716716
goto cleanup;
717-
} else if (msg == NC_MSG_ERROR) {
717+
} else if (msg == NC_MSG_ERROR || reply == NULL) {
718718
WRN("Session %u: failed to receive a reply to <get> of yang-library data.", session->id);
719719
goto cleanup;
720720
}

0 commit comments

Comments
 (0)