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

[PATCH 1/3] tools/libxenstat: don't crash when /sys/class/net can't be opened


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
  • Date: Fri, 16 Oct 2026 09:12:57 +0000
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Fri, 16 Oct 2026 09:14:03 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

getBridge() doesn't check the return value of opendir(), so readdir()
and closedir() are passed a NULL pointer when /sys/class/net can't be
opened, e.g. when sysfs isn't mounted. As getBridge() is called on every
network collection, the libxenstat user (xentop for instance) crashes
instead of simply not finding a bridge.

Return early in that case. The caller's buffer is zero-initialised, so
no bridge is reported, which xenstat_collect_networks() handles since
commit 0c53660c1cf3 ("tools/libxenstat: don't lose all VIFs when dom0
has no Linux bridge").

Fixes: 1fd93d4f8cb8 ("xenstat: Linux dom0 statistics for case we use network 
bonding")
Assisted-by: Claude-Code:claude-opus-5-5
Signed-off-by: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
---
 tools/libs/stat/xenstat_linux.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index 2a7d2f1a96..ec627f3ef5 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -75,6 +75,9 @@ static void getBridge(const char *excludeName, char *result, 
size_t resultLen)
        char tmp[512] = { 0 };
 
        d = opendir("/sys/class/net");
+       if (d == NULL)
+               return;
+
        while ((de = readdir(d)) != NULL) {
                if ((strlen(de->d_name) > 0) && (de->d_name[0] != '.')
                        && (strstr(de->d_name, excludeName) == NULL)) {
-- 
2.53.0



--
Olivier Lambert | Vates CEO

XCP-ng & Xen Orchestra - Vates solutions
Book a meeting with me: https://calrs.vates.tech/u/olivier-lambert
web: https://vates.tech

 


Rackspace

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