[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


  • To: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
  • From: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
  • Date: Fri, 16 Oct 2026 13:55:37 +0200
  • 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:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID"
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Fri, 16 Oct 2026 11:55:52 +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;
> +
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>



 


Rackspace

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