[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools/xenconsoled: fix detection of sscanf() failure in xs_gather()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Bala Andegue François Lionnel <balaandeguefrancoislionnel@xxxxxxxxx>
  • Date: Fri, 27 Nov 2026 23:20:49 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From"
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Fri, 27 Nov 2026 22:21:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.