From: Hangbin Liu Date: Thu, 8 Sep 2016 02:26:57 +0000 (+0800) Subject: ip route: check ftell, fseek return value X-Git-Tag: v4.8.0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bffb68b6c28a942d5341a912f5a11894f8bcf243;p=thirdparty%2Fiproute2.git ip route: check ftell, fseek return value 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 Signed-off-by: Hangbin Liu --- diff --git a/ip/iproute.c b/ip/iproute.c index 0bc013686..98bfad6cb 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -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);