tools/xenstored: Fix off-by-one in dump_state_nodes()
authorJulien Grall <jgrall@amazon.com>
Thu, 29 Jul 2021 09:34:20 +0000 (10:34 +0100)
committerIan Jackson <iwj@xenproject.org>
Fri, 30 Jul 2021 10:02:35 +0000 (11:02 +0100)
commitc85610a3224a89159284f082c8c3dfb842c070fb
tree90269661d48b939f267cae0b06080ad61d145871
parent3747a2bb67daa5a8baeff6cda57dc98a5ef79c3e
tools/xenstored: Fix off-by-one in dump_state_nodes()

The maximum path length supported by Xenstored protocol is
XENSTORE_ABS_PATH_MAX (i.e 3072). This doesn't take into account the
NUL at the end of the path.

However, the code to dump the nodes will allocate a buffer
of XENSTORE_ABS_PATH. As a result it may not be possible to live-update
if there is a node name of XENSTORE_ABS_PATH.

Fix it by allocating a buffer of XENSTORE_ABS_PATH_MAX + 1 characters.

Take the opportunity to pass the max length of the buffer as a
parameter of dump_state_node_tree(). This will be clearer that the
check in the function is linked to the allocation in dump_state_nodes().

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
tools/xenstore/xenstored_core.c