diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2024-10-16 12:52:48 +0200 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2024-10-16 13:30:25 +0200 |
commit | 1350f8d1c19c6010b3b531f6203b2016aa71ce33 (patch) | |
tree | 393ebb79d0609c6393d42afc5ffbdd33be3dd575 /zebra | |
parent | vtysh: make clang-SA happy about reusing stdin (diff) | |
download | frr-1350f8d1c19c6010b3b531f6203b2016aa71ce33.tar.xz frr-1350f8d1c19c6010b3b531f6203b2016aa71ce33.zip |
zebra: don't try to read past EOF
`FILE *` objects are theoretically in an invalid state if you try to use
them past their reporting EOF. Adjust the code to make it correct.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/ipforward_proc.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/zebra/ipforward_proc.c b/zebra/ipforward_proc.c index 08fbfede4..0eae221e1 100644 --- a/zebra/ipforward_proc.c +++ b/zebra/ipforward_proc.c @@ -17,10 +17,15 @@ extern struct zebra_privs_t zserv_privs; static const char proc_net_snmp[] = "/proc/net/snmp"; -static void dropline(FILE *fp) +static bool dropline(FILE *fp) { - while (getc(fp) != '\n') - ; + int ch; + + do { + ch = getc(fp); + } while (ch != EOF && ch != '\n'); + + return ch != EOF; } int ipforward(void) @@ -36,7 +41,10 @@ int ipforward(void) return -1; /* We don't care about the first line. */ - dropline(fp); + if (!dropline(fp)) { + fclose(fp); + return 0; + } /* Get ip_statistics.IpForwarding : 1 => ip forwarding enabled |