ip route: check ftell, fseek return value
Subsystems (2)
PATCH v2 1/1 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 <[email protected]>
Signed-off-by Hangbin Liu <[email protected]>
--- ip/iproute.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
ip/iproute.c +9 -1
@@ -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 );
Signature · 1 line
2.5.5
Stephen Hemminger
AppliedQuoted 5 lines · On Thu, 8 Sep 2016 10:26:57 +0800 Hangbin Liu <[email protected]> wrote:
ftell()may return -1 in error case, which is not handled and therefore pass a negative offset tofseek(). The return code offseek()is also not checked.Reported-by Phil Sutter <[email protected]>Signed-off-by Hangbin Liu <[email protected]>
Applied