]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip route: check ftell, fseek return value
authorHangbin Liu <liuhangbin@gmail.com>
Thu, 8 Sep 2016 02:26:57 +0000 (10:26 +0800)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 20 Sep 2016 16:52:35 +0000 (09:52 -0700)
ftell() may return -1 in error case, which is not handled and
therefore pass a negative offset to fseek(). The return code of
fseek() is also not checked.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
ip/iproute.c

index 0bc0136860a9a020de835ac79c2c0abb421de7f7..98bfad6cb7bc09b726501de810baf96906296428 100644 (file)
@@ -1862,6 +1862,11 @@ static int iproute_restore(void)
                exit(-1);
 
        pos = ftell(stdin);
+       if (pos == -1) {
+               perror("Failed to restore: ftell");
+               exit(-1);
+       }
+
        for (prio = 0; prio < 3; prio++) {
                int err;
 
@@ -1869,7 +1874,10 @@ static int iproute_restore(void)
                if (err)
                        exit(err);
 
-               fseek(stdin, pos, SEEK_SET);
+               if (fseek(stdin, pos, SEEK_SET) == -1) {
+                       perror("Failed to restore: fseek");
+                       exit(-1);
+               }
        }
 
        exit(0);