[PATCH 11/12] sandbox: fix behavior with images >= 4G on 32-bit

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Sep 30 03:20:04 EDT 2020


hf->base may remain uninitialized if an image is > 4G, but sandbox
barebox is compiled for 32-bit. Fix this.

Reported-by: clang-analyzer-10
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/os/common.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 43ee95edb6e3..72bb35464f25 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -289,6 +289,7 @@ static int add_image(const char *_str, char *devname_template, int *devname_numb
 	hf->fd = fd;
 	hf->filename = filename;
 	hf->is_blockdev = blkdev;
+	hf->base = (unsigned long)MAP_FAILED;
 
 	if (fd < 0) {
 		perror("open");
@@ -311,15 +312,16 @@ static int add_image(const char *_str, char *devname_template, int *devname_numb
 		if (!cdev)
 			hf->is_blockdev = 1;
 	}
-	if (hf->size <= SIZE_MAX)
+	if (hf->size <= SIZE_MAX) {
 		hf->base = (unsigned long)mmap(NULL, hf->size,
 				PROT_READ | (readonly ? 0 : PROT_WRITE),
 				MAP_SHARED, fd, 0);
-	else
-		printf("warning: %s: contiguous map failed\n", filename);
 
-	if (hf->base == (unsigned long)MAP_FAILED)
-		printf("warning: mmapping %s failed: %s\n", filename, strerror(errno));
+		if (hf->base == (unsigned long)MAP_FAILED)
+			printf("warning: mmapping %s failed: %s\n", filename, strerror(errno));
+	} else {
+		printf("warning: %s: contiguous map failed\n", filename);
+	}
 
 	if (blkdev && hf->size % 512 != 0) {
 		printf("warning: registering %s as block device failed: invalid block size\n",
-- 
2.28.0




More information about the barebox mailing list