tools/xenstored: Don't assume errno will not be overwritten in lu_arch()
authorJulien Grall <jgrall@amazon.com>
Fri, 30 Jul 2021 15:14:14 +0000 (16:14 +0100)
committerJulien Grall <jgrall@amazon.com>
Fri, 30 Jul 2021 15:14:39 +0000 (16:14 +0100)
commite066ca5acc2ee3b5db5c005e1a548b05e753e07d
treefc3aae4c33331e46ad82f049f4057313dffaccf5
parent604551fb763c4c70123f642a9b2866890790e2b2
tools/xenstored: Don't assume errno will not be overwritten in lu_arch()

At the moment, do_control_lu() will set errno to 0 before calling
lu_arch() and then check errno. The expectation is nothing in lu_arch()
will change the value unless there is an error.

However, per errno(3), a function that succeeds is allowed to change
errno. In fact, syslog() will overwrite errno if the logs are rotated
at the time it is called.

To prevent any further issue, errno is now always set before
returning NULL.

Additionally, errno is only checked when returning NULL so the client
can see the error message if there is any.

Reported-by: Michael Kurth <mku@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
tools/xenstore/xenstored_control.c