]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: don't try to read past EOF
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 10:52:48 +0000 (12:52 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 11:30:25 +0000 (13:30 +0200)
`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>
zebra/ipforward_proc.c

index 08fbfede42aff314518df36463ec7a7b44883c81..0eae221e1e11b8fc392aeba6f38c3f5341d1a1dc 100644 (file)
@@ -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