Skip to contentSkip to conversation

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

PATCH In review Peter Maydell 2 participants 3 messages Aug 5, 2016 – Aug 8, 2016

lore
Share & tools
lore
#0 lore raw

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

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()).

---
 hw/sparc/leon3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sparc/leon3.c +5 -1
index dbae41f..6e16478 100644
@@ -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",
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Peter Maydell

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 Peter!

Quoted 23 lines
---
 hw/sparc/leon3.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/sparc/leon3.c +5 -1
index dbae41f..6e16478 100644
@@ -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",
#2 lore raw
Quoted 7 lines · Fabien Chouteau
Quoted 4 lines · Peter Maydell

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