|
[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
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |