|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [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;
> +
We might want a message telling it failed as it's already done in the
file for SYSFS_VBD_PATH.
I'd propose:
if (d == NULL) {
perror("Error opening /sys/class/net");
return;
}
Reviewed-by: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
--
Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |