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

[PATCH 3/3] tools/libxenstat: fix output initialisation in parseNetDevLine()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
  • Date: Fri, 16 Oct 2026 09:12:59 +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:09 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

parseNetDevLine() zeroes all the outputs it is passed before parsing the
line, but *rxPackets is zeroed twice while *rxMcast isn't zeroed at all,
so it would be left untouched for a line that doesn't parse.

Also, iface is cleared with memset(iface, 0, sizeof(*iface)), which only
covers the first byte. The function isn't told the buffer size, and an
empty string is all that's needed, so write the terminator directly.

No functional change intended: the only caller passes NULL for rxMcast.

Assisted-by: Claude-Code:claude-opus-5-5
Signed-off-by: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
---
 tools/libs/stat/xenstat_linux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index 97f7fa9f87..aebd848722 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -123,7 +123,7 @@ static int parseNetDevLine(char *line, char *iface, 
unsigned long long *rxBytes,
 
        /* Initialize all variables called has passed as non-NULL to zeros */
        if (iface != NULL)
-               memset(iface, 0, sizeof(*iface));
+               iface[0] = '\0';
        if (rxBytes != NULL)
                *rxBytes = 0;
        if (rxPackets != NULL)
@@ -136,10 +136,10 @@ static int parseNetDevLine(char *line, char *iface, 
unsigned long long *rxBytes,
                *rxFifo = 0;
        if (rxFrames != NULL)
                *rxFrames = 0;
-       if (rxPackets != NULL)
-               *rxPackets = 0;
        if (rxComp != NULL)
                *rxComp = 0;
+       if (rxMcast != NULL)
+               *rxMcast = 0;
        if (txBytes != NULL)
                *txBytes = 0;
        if (txPackets != 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®.