|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] tools/xenconsoled: fix detection of sscanf() failure in xs_gather()
xs_gather() only treats a return value of 0 from sscanf() as a parse
failure. However, sscanf() returns EOF if the input ends before the
first conversion, e.g. when the xenstore node holds an empty string.
In that case the result is left untouched, but xs_gather() still
reports success.
console_create_ring() then goes on with ring_ref or remote_port
uninitialised, while a non-numeric value such as "abc" is correctly
rejected with EINVAL.
All callers pass a single conversion, so treat any return value other
than 1 as an error.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Bala Andegue François Lionnel
<balaandeguefrancoislionnel@xxxxxxxxx>
---
Notes:
Tested in a nested setup (Xen built from staging, busybox dom0 and a PV
guest under QEMU/KVM). With a temporary debug log in
console_create_ring(), writing "" to the guest's console/port node from
dom0 gave err=0 before this patch, and EINVAL after it, the same as for
"abc".
tools/console/daemon/io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index b6c46d11dea7..728dd01fba31 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -654,7 +654,7 @@ static int xs_gather(struct xs_handle *xs, const char *dir,
...)
break;
}
if (fmt) {
- if (sscanf(p, fmt, result) == 0)
+ if (sscanf(p, fmt, result) != 1)
ret = EINVAL;
free(p);
} else
base-commit: abc47aca98fa87e9fdebd0e9f7fbbbaa482056fb
--
2.39.2
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |