From 2a4e2e4919d1fcb915f1b33f9396aad5dc4616f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Wed, 26 Jul 2017 23:42:07 -0300 Subject: loader: check get_image_size() return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit since a negative value means it errored. hw/core/loader.c:149:9: warning: Loss of sign in implicit conversion if (size > max_sz) { ^~~~ hw/core/loader.c:171:9: warning: Loss of sign in implicit conversion if (size > memory_region_size(mr)) { ^~~~ Reported-by: Clang Static Analyzer Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake Reviewed-by: Alistair Francis Signed-off-by: Michael Tokarev --- hw/core/loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw/core/loader.c') diff --git a/hw/core/loader.c b/hw/core/loader.c index e5e8cbb..ebe574c 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -146,7 +146,7 @@ int load_image_targphys_as(const char *filename, int size; size = get_image_size(filename); - if (size > max_sz) { + if (size < 0 || size > max_sz) { return -1; } if (size > 0) { @@ -168,7 +168,7 @@ int load_image_mr(const char *filename, MemoryRegion *mr) size = get_image_size(filename); - if (size > memory_region_size(mr)) { + if (size < 0 || size > memory_region_size(mr)) { return -1; } if (size > 0) { -- cgit v1.1