|
|
36cfb7 |
From 5ae0f31d9c5d40dbf9eaf00435b9df1968109f5e Mon Sep 17 00:00:00 2001
|
|
|
36cfb7 |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
36cfb7 |
Date: Mon, 29 Apr 2019 20:08:07 +0200
|
|
|
36cfb7 |
Subject: [PATCH] ifstat, nstat: Check fdopen() return value
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
|
|
|
36cfb7 |
Upstream Status: iproute2.git commit 6d02518fdc37e
|
|
|
36cfb7 |
|
|
|
36cfb7 |
commit 6d02518fdc37eb12abff67b6f8c741fbd81dce72
|
|
|
36cfb7 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
36cfb7 |
Date: Thu Aug 24 11:46:31 2017 +0200
|
|
|
36cfb7 |
|
|
|
36cfb7 |
ifstat, nstat: Check fdopen() return value
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Prevent passing NULL FILE pointer to fgets() later.
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Fix both tools in a single patch since the code changes are basically
|
|
|
36cfb7 |
identical.
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
36cfb7 |
---
|
|
|
36cfb7 |
misc/ifstat.c | 16 +++++++++++-----
|
|
|
36cfb7 |
misc/nstat.c | 16 +++++++++++-----
|
|
|
36cfb7 |
2 files changed, 22 insertions(+), 10 deletions(-)
|
|
|
36cfb7 |
|
|
|
36cfb7 |
diff --git a/misc/ifstat.c b/misc/ifstat.c
|
|
|
36cfb7 |
index 1be21703bf14c..ac3eff6b870a9 100644
|
|
|
36cfb7 |
--- a/misc/ifstat.c
|
|
|
36cfb7 |
+++ b/misc/ifstat.c
|
|
|
36cfb7 |
@@ -992,12 +992,18 @@ int main(int argc, char *argv[])
|
|
|
36cfb7 |
&& verify_forging(fd) == 0) {
|
|
|
36cfb7 |
FILE *sfp = fdopen(fd, "r");
|
|
|
36cfb7 |
|
|
|
36cfb7 |
- load_raw_table(sfp);
|
|
|
36cfb7 |
- if (hist_db && source_mismatch) {
|
|
|
36cfb7 |
- fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
|
|
|
36cfb7 |
- hist_db = NULL;
|
|
|
36cfb7 |
+ if (!sfp) {
|
|
|
36cfb7 |
+ fprintf(stderr, "ifstat: fdopen failed: %s\n",
|
|
|
36cfb7 |
+ strerror(errno));
|
|
|
36cfb7 |
+ close(fd);
|
|
|
36cfb7 |
+ } else {
|
|
|
36cfb7 |
+ load_raw_table(sfp);
|
|
|
36cfb7 |
+ if (hist_db && source_mismatch) {
|
|
|
36cfb7 |
+ fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
|
|
|
36cfb7 |
+ hist_db = NULL;
|
|
|
36cfb7 |
+ }
|
|
|
36cfb7 |
+ fclose(sfp);
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
- fclose(sfp);
|
|
|
36cfb7 |
} else {
|
|
|
36cfb7 |
if (fd >= 0)
|
|
|
36cfb7 |
close(fd);
|
|
|
36cfb7 |
diff --git a/misc/nstat.c b/misc/nstat.c
|
|
|
36cfb7 |
index 1212b1f2c8128..a4dd405d43a93 100644
|
|
|
36cfb7 |
--- a/misc/nstat.c
|
|
|
36cfb7 |
+++ b/misc/nstat.c
|
|
|
36cfb7 |
@@ -706,12 +706,18 @@ int main(int argc, char *argv[])
|
|
|
36cfb7 |
&& verify_forging(fd) == 0) {
|
|
|
36cfb7 |
FILE *sfp = fdopen(fd, "r");
|
|
|
36cfb7 |
|
|
|
36cfb7 |
- load_good_table(sfp);
|
|
|
36cfb7 |
- if (hist_db && source_mismatch) {
|
|
|
36cfb7 |
- fprintf(stderr, "nstat: history is stale, ignoring it.\n");
|
|
|
36cfb7 |
- hist_db = NULL;
|
|
|
36cfb7 |
+ if (!sfp) {
|
|
|
36cfb7 |
+ fprintf(stderr, "nstat: fdopen failed: %s\n",
|
|
|
36cfb7 |
+ strerror(errno));
|
|
|
36cfb7 |
+ close(fd);
|
|
|
36cfb7 |
+ } else {
|
|
|
36cfb7 |
+ load_good_table(sfp);
|
|
|
36cfb7 |
+ if (hist_db && source_mismatch) {
|
|
|
36cfb7 |
+ fprintf(stderr, "nstat: history is stale, ignoring it.\n");
|
|
|
36cfb7 |
+ hist_db = NULL;
|
|
|
36cfb7 |
+ }
|
|
|
36cfb7 |
+ fclose(sfp);
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
- fclose(sfp);
|
|
|
36cfb7 |
} else {
|
|
|
36cfb7 |
if (fd >= 0)
|
|
|
36cfb7 |
close(fd);
|
|
|
36cfb7 |
--
|
|
|
e138d9 |
2.21.0
|
|
|
36cfb7 |
|