diff mbox series

[3/6] hw/mips/boston: Check for error return from boston_fdt_filter()

Message ID 20250206151214.2947842-4-peter.maydell@linaro.org
State New
Headers show
Series hw: Centralize handling, improve error messages for -machine dumpdtb | expand

Commit Message

Peter Maydell Feb. 6, 2025, 3:12 p.m. UTC
The function boston_fdt_filter() can return NULL on errors (in which
case it will print an error message).  When we call this from the
non-FIT-image codepath, we aren't checking the return value, so we
will plough on with a NULL pointer, and segfault in fdt_totalsize().
Check for errors here.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/mips/boston.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Philippe Mathieu-Daudé Feb. 10, 2025, 10:48 a.m. UTC | #1
On 6/2/25 16:12, Peter Maydell wrote:
> The function boston_fdt_filter() can return NULL on errors (in which
> case it will print an error message).  When we call this from the
> non-FIT-image codepath, we aren't checking the return value, so we
> will plough on with a NULL pointer, and segfault in fdt_totalsize().
> Check for errors here.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/mips/boston.c | 4 ++++
>   1 file changed, 4 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 364c328032a..f0e9a2461a0 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -810,6 +810,10 @@  static void boston_mach_init(MachineState *machine)
 
             dtb_load_data = boston_fdt_filter(s, dtb_file_data,
                                               NULL, &dtb_vaddr);
+            if (!dtb_load_data) {
+                /* boston_fdt_filter() already printed the error for us */
+                exit(1);
+            }
 
             /* Calculate real fdt size after filter */
             dt_size = fdt_totalsize(dtb_load_data);