23b1b8
From 604b607d8ac91eb8afc0b6e3d917d5c073096103 Mon Sep 17 00:00:00 2001
23b1b8
From: Phillip Lougher <phillip@squashfs.org.uk>
23b1b8
Date: Wed, 11 Jun 2014 04:51:37 +0100
23b1b8
Subject: mksquashfs: ensure value does not overflow a signed int in -mem
23b1b8
 option
23b1b8
23b1b8
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
23b1b8
23b1b8
diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
23b1b8
index 5370ecf..9676dc8 100644
23b1b8
--- a/squashfs-tools/mksquashfs.c
23b1b8
+++ b/squashfs-tools/mksquashfs.c
23b1b8
@@ -5193,7 +5193,16 @@ print_compressor_options:
23b1b8
 					 argv[0]);
23b1b8
 				exit(1);
23b1b8
 			}
23b1b8
-			/* convert from bytes to Mbytes */
23b1b8
+
23b1b8
+			/*
23b1b8
+			 * convert from bytes to Mbytes, ensuring the value
23b1b8
+			 * does not overflow a signed int
23b1b8
+			 */
23b1b8
+			if(number >= (1LL << 51)) {
23b1b8
+				ERROR("%s: -mem invalid mem size\n", argv[0]);
23b1b8
+				exit(1);
23b1b8
+			}
23b1b8
+
23b1b8
 			total_mem = number / 1048576;
23b1b8
 			if(total_mem < (SQUASHFS_LOWMEM / SQUASHFS_TAKE)) {
23b1b8
 				ERROR("%s: -mem should be %d Mbytes or "
23b1b8
-- 
23b1b8
cgit v0.10.1
23b1b8