shithub: libmujs

Download patch

ref: 5e3e9fdde43fa7c5243f3180405ddaeaf2329880
parent: 13c7d26dda60f87aad9e0d7bb94f11b5472782a1
author: Tor Andersson <tor.andersson@artifex.com>
date: Mon Jan 5 08:03:30 EST 2015

Check error for all fseek/ftell calls.

--- a/jsstate.c
+++ b/jsstate.c
@@ -83,8 +83,17 @@
 		fclose(f);
 		js_error(J, "cannot seek in file: '%s'", filename);
 	}
+
 	n = ftell(f);
-	fseek(f, 0, SEEK_SET);
+	if (n < 0) {
+		fclose(f);
+		js_error(J, "cannot tell in file: '%s'", filename);
+	}
+
+	if (fseek(f, 0, SEEK_SET) < 0) {
+		fclose(f);
+		js_error(J, "cannot seek in file: '%s'", filename);
+	}
 
 	s = js_malloc(J, n + 1); /* add space for string terminator */
 	if (!s) {
--- a/main.c
+++ b/main.c
@@ -59,8 +59,17 @@
 		fclose(f);
 		js_error(J, "cannot seek in file: '%s'", filename);
 	}
+
 	n = ftell(f);
-	fseek(f, 0, SEEK_SET);
+	if (n < 0) {
+		fclose(f);
+		js_error(J, "cannot tell in file: '%s'", filename);
+	}
+
+	if (fseek(f, 0, SEEK_SET) < 0) {
+		fclose(f);
+		js_error(J, "cannot seek in file: '%s'", filename);
+	}
 
 	s = malloc(n + 1);
 	if (!s) {