[Qemu-devel] [PATCH] PPC: e500: Add check for NULL return value from qemu_find_file.

Nia Alarie posted 1 patch 7 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180303130226.26906-1-nia.alarie@gmail.com
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test docker-quick@centos6 passed
Test ppcbe passed
Test ppcle passed
Test s390x passed
hw/ppc/e500.c | 4 ++++
1 file changed, 4 insertions(+)
[Qemu-devel] [PATCH] PPC: e500: Add check for NULL return value from qemu_find_file.
Posted by Nia Alarie 7 years, 7 months ago
This prints a message and exits if the e500 BIOS firmware can't
be found, to avoid dereferencing a null pointer.

Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
---
 hw/ppc/e500.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index a40d3ec3e3..6ce03d6ff4 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1005,6 +1005,10 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         }
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    if (!filename) {
+        error_report("Could not find firmware '%s'", bios_name);
+        exit(1);
+    }
 
     bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
                          1, PPC_ELF_MACHINE, 0, 0);
-- 
2.16.2


Re: [Qemu-devel] [PATCH] PPC: e500: Add check for NULL return value from qemu_find_file.
Posted by David Gibson 7 years, 7 months ago
On Sat, Mar 03, 2018 at 01:02:26PM +0000, Nia Alarie wrote:
> This prints a message and exits if the e500 BIOS firmware can't
> be found, to avoid dereferencing a null pointer.
> 
> Signed-off-by: Nia Alarie <nia.alarie@gmail.com>

Applied to ppc-for-2.12, thanks.

> ---
>  hw/ppc/e500.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index a40d3ec3e3..6ce03d6ff4 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -1005,6 +1005,10 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
>          }
>      }
>      filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> +    if (!filename) {
> +        error_report("Could not find firmware '%s'", bios_name);
> +        exit(1);
> +    }
>  
>      bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
>                           1, PPC_ELF_MACHINE, 0, 0);

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH] PPC: e500: Add check for NULL return value from qemu_find_file.
Posted by David Gibson 7 years, 7 months ago
On Mon, Mar 05, 2018 at 10:51:52AM +1100, David Gibson wrote:
> On Sat, Mar 03, 2018 at 01:02:26PM +0000, Nia Alarie wrote:
> > This prints a message and exits if the e500 BIOS firmware can't
> > be found, to avoid dereferencing a null pointer.
> > 
> > Signed-off-by: Nia Alarie <nia.alarie@gmail.com>
> 
> Applied to ppc-for-2.12, thanks.

Sorry, I take that back.  This has been obsoleted by other changes to
the e500 image load path.
> 
> > ---
> >  hw/ppc/e500.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> > index a40d3ec3e3..6ce03d6ff4 100644
> > --- a/hw/ppc/e500.c
> > +++ b/hw/ppc/e500.c
> > @@ -1005,6 +1005,10 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
> >          }
> >      }
> >      filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> > +    if (!filename) {
> > +        error_report("Could not find firmware '%s'", bios_name);
> > +        exit(1);
> > +    }
> >  
> >      bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
> >                           1, PPC_ELF_MACHINE, 0, 0);
> 



-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson