netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 iproute2] ip route: check ftell, fseek return value
@ 2016-09-08  2:26 Hangbin Liu
  2016-09-20 16:53 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Hangbin Liu @ 2016-09-08  2:26 UTC (permalink / raw)
  To: netdev; +Cc: David Laight, Phil Sutter, Stephen Hemminger, Hangbin Liu

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 | 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCHv2 iproute2] ip route: check ftell, fseek return value
  2016-09-08  2:26 [PATCHv2 iproute2] ip route: check ftell, fseek return value Hangbin Liu
@ 2016-09-20 16:53 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2016-09-20 16:53 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, David Laight, Phil Sutter

On Thu,  8 Sep 2016 10:26:57 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> 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>

Applied

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-20 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-08  2:26 [PATCHv2 iproute2] ip route: check ftell, fseek return value Hangbin Liu
2016-09-20 16:53 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).