diff mbox

hw/sparc/leon3: Don't call get_image_size() on a NULL pointer

Message ID 1470391439-28427-1-git-send-email-peter.maydell@linaro.org
State Accepted
Commit 47dc0ec576c3d8748985e34d273c8dc0465c5ddb
Headers show

Commit Message

Peter Maydell Aug. 5, 2016, 10:03 a.m. UTC
get_image_size() doesn't handle being passed a NULL pointer, so
avoid doing that. Spotted by the clang ub sanitizer (which notices
the attempt to pass NULL to open()).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 hw/sparc/leon3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.7.4

Comments

Peter Maydell Aug. 8, 2016, 1:24 p.m. UTC | #1
On 5 August 2016 at 13:59, Fabien Chouteau <chouteau@adacore.com> wrote:
> On 08/05/2016 12:03 PM, Peter Maydell wrote:

>> get_image_size() doesn't handle being passed a NULL pointer, so

>> avoid doing that. Spotted by the clang ub sanitizer (which notices

>> the attempt to pass NULL to open()).

>>

>

> Looks good.


Thanks; I've applied this patch to master.

-- PMM
diff mbox

Patch

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index dbae41f..6e16478 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -171,7 +171,11 @@  static void leon3_generic_hw_init(MachineState *machine)
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
-    bios_size = get_image_size(filename);
+    if (filename) {
+        bios_size = get_image_size(filename);
+    } else {
+        bios_size = -1;
+    }
 
     if (bios_size > prom_size) {
         fprintf(stderr, "qemu: could not load prom '%s': file too big\n",