XML parser BUGFIX parsing empty data as RPC, Reply or Notification
RPC/Notification cannot be empty, in case of Reply the top-level
RPC node must be correctly taken from the original RPC.
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 83dd172..0fae90c 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -555,10 +555,18 @@
return NULL;
}
- if (!(*root)) {
- /* empty tree - no work is needed */
- lyd_validate(&result, options, ctx);
- return result;
+ if (!(*root) && !(options & LYD_OPT_RPCREPLY)) {
+ /* empty tree */
+ if (options & (LYD_OPT_RPC | LYD_OPT_NOTIF)) {
+ /* error, top level node identify RPC and Notification */
+ LOGERR(LY_EINVAL, "%s: *root identifies RPC/Notification so it cannot be NULL.", __func__);
+ return NULL;
+ } else if (!(options & LYD_OPT_RPCREPLY)) {
+ /* others - no work is needed, just check for missing mandatory nodes */
+ lyd_validate(&result, options, ctx);
+ return result;
+ }
+ /* continue with empty RPC reply, for which we need RPC */
}
unres = calloc(1, sizeof *unres);
@@ -613,7 +621,7 @@
}
}
- if (!(options & LYD_OPT_NOSIBLINGS)) {
+ if ((*root) && !(options & LYD_OPT_NOSIBLINGS)) {
/* locate the first root to process */
if ((*root)->parent) {
xmlstart = (*root)->parent->child;