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 <p...@nwl.cc> Signed-off-by: Hangbin Liu <liuhang...@gmail.com> --- ip/iproute.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index 3da23af..ba877dc 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1859,7 +1859,11 @@ static int iproute_restore(void) if (route_dump_check_magic()) exit(-1); - pos = ftell(stdin); + if ((pos = ftell(stdin)) == -1) { + perror("Failed to restore: ftell"); + exit(errno); + } + for (prio = 0; prio < 3; prio++) { int err; @@ -1867,7 +1871,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(errno); + } } exit(0); -- 2.5.5