ifstat, nstat: Check fdopen() return value
Prevent passing NULL FILE pointer to fgets() later. Fix both tools in a single patch since the code changes are basically identical. Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
parent
ae4e21c93f
commit
6d02518fdc
|
|
@ -992,12 +992,18 @@ int main(int argc, char *argv[])
|
||||||
&& verify_forging(fd) == 0) {
|
&& verify_forging(fd) == 0) {
|
||||||
FILE *sfp = fdopen(fd, "r");
|
FILE *sfp = fdopen(fd, "r");
|
||||||
|
|
||||||
load_raw_table(sfp);
|
if (!sfp) {
|
||||||
if (hist_db && source_mismatch) {
|
fprintf(stderr, "ifstat: fdopen failed: %s\n",
|
||||||
fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
|
strerror(errno));
|
||||||
hist_db = NULL;
|
close(fd);
|
||||||
|
} else {
|
||||||
|
load_raw_table(sfp);
|
||||||
|
if (hist_db && source_mismatch) {
|
||||||
|
fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
|
||||||
|
hist_db = NULL;
|
||||||
|
}
|
||||||
|
fclose(sfp);
|
||||||
}
|
}
|
||||||
fclose(sfp);
|
|
||||||
} else {
|
} else {
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
16
misc/nstat.c
16
misc/nstat.c
|
|
@ -706,12 +706,18 @@ int main(int argc, char *argv[])
|
||||||
&& verify_forging(fd) == 0) {
|
&& verify_forging(fd) == 0) {
|
||||||
FILE *sfp = fdopen(fd, "r");
|
FILE *sfp = fdopen(fd, "r");
|
||||||
|
|
||||||
load_good_table(sfp);
|
if (!sfp) {
|
||||||
if (hist_db && source_mismatch) {
|
fprintf(stderr, "nstat: fdopen failed: %s\n",
|
||||||
fprintf(stderr, "nstat: history is stale, ignoring it.\n");
|
strerror(errno));
|
||||||
hist_db = NULL;
|
close(fd);
|
||||||
|
} else {
|
||||||
|
load_good_table(sfp);
|
||||||
|
if (hist_db && source_mismatch) {
|
||||||
|
fprintf(stderr, "nstat: history is stale, ignoring it.\n");
|
||||||
|
hist_db = NULL;
|
||||||
|
}
|
||||||
|
fclose(sfp);
|
||||||
}
|
}
|
||||||
fclose(sfp);
|
|
||||||
} else {
|
} else {
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue