diff mbox

[1/2] xenstore: send error earlier in do_mkdir

Message ID 1469024022-6505-2-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu July 20, 2016, 2:13 p.m. UTC
XenServer's coverity instance complains that a few lines below
create_node dereferences NULL if name == NULL. It however fails to
figure out that if node is NULL, errno won't be ENOENT, so do_mkdir
should have bailed before create_node.

That said, it would be good if we don't need to go through the hops.  We
can bail earlier if name is NULL.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/xenstore/xenstored_core.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Ian Jackson July 20, 2016, 2:25 p.m. UTC | #1
Wei Liu writes ("[PATCH 1/2] xenstore: send error earlier in do_mkdir"):
> XenServer's coverity instance complains that a few lines below
> create_node dereferences NULL if name == NULL. It however fails to
> figure out that if node is NULL, errno won't be ENOENT, so do_mkdir
> should have bailed before create_node.
> 
> That said, it would be good if we don't need to go through the hops.  We
> can bail earlier if name is NULL.

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
diff mbox

Patch

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index ffc0634..5b2a49b 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -981,6 +981,12 @@  static void do_mkdir(struct connection *conn, struct buffered_data *in)
 	struct node *node;
 	const char *name = onearg(in);
 
+	if (!name) {
+		errno = EINVAL;
+		send_error(conn, errno);
+		return;
+	}
+
 	name = canonicalize(conn, name);
 	node = get_node(conn, in, name, XS_PERM_WRITE);