|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/3] tools/libxenstat: don't skip the /proc/net/dev check after a failure
xenstat_collect_networks() opens /proc/net/dev once and validates its
header before using it. If reading the header fails, or the header isn't
the expected one, an error is returned but the stream is left open in
priv->procnetdev. The next call then finds the stream already open,
skips the validation and parses the file anyway.
Close the stream and clear the pointer on both error paths, so that the
validation is done again on the next call.
Fixes: 49839b535b78 ("Add xenstat framework.")
Assisted-by: Claude-Code:claude-opus-5-5
Signed-off-by: Olivier Lambert <olivier.lambert@xxxxxxxxxx>
---
tools/libs/stat/xenstat_linux.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index ec627f3ef5..97f7fa9f87 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -296,12 +296,16 @@ int xenstat_collect_networks(xenstat_node * node)
if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
priv->procnetdev) != 1) {
perror("Error reading /proc/net/dev header");
+ fclose(priv->procnetdev);
+ priv->procnetdev = NULL;
return 0;
}
header[sizeof(PROCNETDEV_HEADER) - 1] = '\0';
if (strcmp(header, PROCNETDEV_HEADER) != 0) {
fprintf(stderr,
"Unexpected /proc/net/dev format\n");
+ fclose(priv->procnetdev);
+ priv->procnetdev = NULL;
return 0;
}
}
--
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 |