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