tools: Fix heap buffer overflow in ideviceimagemounter
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 52b0666..511583e 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -377,8 +377,11 @@
 				fprintf(stderr, "Error opening signature file '%s': %s\n", image_sig_path, strerror(errno));
 				goto leave;
 			}
-			fstat(fileno(f), &fst);
-			sig = malloc(sig_length);
+			if (fstat(fileno(f), &fst) != 0) {
+				fprintf(stderr, "Error: fstat: %s\n", strerror(errno));
+				goto leave;
+			}
+			sig = malloc(fst.st_size);
 			sig_length = fread(sig, 1, fst.st_size, f);
 			fclose(f);
 			if (sig_length == 0) {