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