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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ip/iproute.c b/ip/iproute.c index 3da23af..c06a474 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1860,6 +1860,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; @@ -1867,7 +1872,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); -- 2.5.5