Skip to content

Commit 6b281ff

Browse files
committed
client session BUGFIX handle data rpc replies with only default values
Fixes #392
1 parent 7e5f7b0 commit 6b281ff

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/session_client.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,13 +1661,8 @@ parse_reply(struct ly_ctx *ctx, struct lyxml_elem *xml, struct nc_rpc *rpc, int
16611661
struct nc_rpc_act_generic *rpc_gen;
16621662
int i, data_parsed = 0;
16631663

1664-
if (!xml->child) {
1665-
ERR("An empty <rpc-reply>.");
1666-
return NULL;
1667-
}
1668-
16691664
/* rpc-error */
1670-
if (!strcmp(xml->child->name, "rpc-error") && xml->child->ns && !strcmp(xml->child->ns->value, NC_NS_BASE)) {
1665+
if (xml->child && !strcmp(xml->child->name, "rpc-error") && xml->child->ns && !strcmp(xml->child->ns->value, NC_NS_BASE)) {
16711666
/* count and check elements */
16721667
i = 0;
16731668
LY_TREE_FOR(xml->child, iter) {
@@ -1707,7 +1702,7 @@ parse_reply(struct ly_ctx *ctx, struct lyxml_elem *xml, struct nc_rpc *rpc, int
17071702
}
17081703

17091704
/* ok */
1710-
} else if (!strcmp(xml->child->name, "ok") && xml->child->ns && !strcmp(xml->child->ns->value, NC_NS_BASE)) {
1705+
} else if (xml->child && !strcmp(xml->child->name, "ok") && xml->child->ns && !strcmp(xml->child->ns->value, NC_NS_BASE)) {
17111706
if (xml->child->next) {
17121707
ERR("<rpc-reply> content mismatch (<ok> and <%s>).", xml->child->next->name);
17131708
return NULL;
@@ -1742,7 +1737,8 @@ parse_reply(struct ly_ctx *ctx, struct lyxml_elem *xml, struct nc_rpc *rpc, int
17421737

17431738
case NC_RPC_GETCONFIG:
17441739
case NC_RPC_GET:
1745-
if (!xml->child->child) {
1740+
/* we should definitely have received at least an empty "data" element even on empty reply, but fine */
1741+
if (!xml->child || !xml->child->child) {
17461742
/* we did not receive any data */
17471743
data_rpl = malloc(sizeof *data_rpl);
17481744
if (!data_rpl) {
@@ -1786,7 +1782,7 @@ parse_reply(struct ly_ctx *ctx, struct lyxml_elem *xml, struct nc_rpc *rpc, int
17861782
case NC_RPC_VALIDATE:
17871783
case NC_RPC_SUBSCRIBE:
17881784
/* there is no output defined */
1789-
ERR("Unexpected data reply (root elem \"%s\").", xml->child->name);
1785+
ERR("Unexpected data reply (root elem \"%s\").", xml->child ? xml->child->name : NULL);
17901786
return NULL;
17911787
default:
17921788
ERRINT;
@@ -1804,6 +1800,13 @@ parse_reply(struct ly_ctx *ctx, struct lyxml_elem *xml, struct nc_rpc *rpc, int
18041800
if (!data_parsed) {
18051801
data_rpl->data = lyd_parse_xml(ctx, &xml->child, LYD_OPT_RPCREPLY | LYD_OPT_DESTRUCT | parseroptions,
18061802
rpc_act, NULL);
1803+
if (!ly_errno && !data_rpl->data->child) {
1804+
ERR("An empty data <rpc-reply>.");
1805+
lyd_free_withsiblings(rpc_act);
1806+
lyd_free(data_rpl->data);
1807+
free(data_rpl);
1808+
return NULL;
1809+
}
18071810
} else {
18081811
/* <get>, <get-config> */
18091812
data_rpl->data = data;

0 commit comments

Comments
 (0)