Skip to contentSkip to conversation

ip route: check ftell, fseek return value

PATCH Applied Hangbin Liu 2 participants 2 messages Sep 8, 2016 – Sep 20, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

---
 ip/iproute.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
ip/iproute.c +9 -1
index 3da23af..c06a474 100644
@@ -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