qemu-e2k/include/hw
Peter Maydell a1ecb43818 elf_ops: Don't try to g_mapped_file_unref(NULL)
Calling g_mapped_file_unref() on a NULL pointer is not valid, and
glib will assert if you try it.

$ qemu-system-arm -M virt -display none -device loader,file=/tmp/bad.elf
qemu-system-arm: -device loader,file=/tmp/bad.elf: GLib: g_mapped_file_unref: assertion 'file != NULL' failed

(One way to produce an ELF file that fails like this is to copy just
the first 16 bytes of a valid ELF file; this is sufficient to fool
the code in load_elf_ram_sym() into thinking it's an ELF file and
calling load_elf32() or load_elf64().)

The failure-exit path in load_elf can be reached from various points
in execution, and for some of those we haven't yet called
g_mapped_file_new_from_fd().  Add a condition to the unref call so we
only call it if we successfully created the GMappedFile to start with.

This will fix the assertion; for the specific case of the generic
loader it will then fall back from "guess this is an ELF file" to
"maybe it's a uImage or a hex file" and eventually to "just load as
a raw data file".

Reported-by: Randy Yates <yates@ieee.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20200423202011.32686-1-peter.maydell@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-05-04 14:35:23 +02:00
..
acpi acpi: Use macro for table-loader file name 2020-04-13 06:55:54 -04:00
adc
arm msf2: Add EMAC block to SmartFusion2 SoC 2020-04-30 11:52:28 +01:00
audio
block
char hw/char/cadence_uart: add clock support 2020-04-30 15:35:41 +01:00
core x86 and machine queue for 5.0 soft freeze 2020-03-19 14:22:46 +00:00
cpu
cris
display hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
dma hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
firmware
gpio nrf51: Fix last GPIO CNF address 2020-04-30 11:52:27 +01:00
hyperv
i2c smbus: Fix spd_data_generate() error API violation 2020-04-29 08:01:52 +02:00
i386 hw/i386: Introduce apicid functions inside X86MachineState 2020-03-31 19:13:32 -03:00
ide hw/ide: Move MAX_IDE_DEVS define to hw/ide/internal.h 2020-03-17 12:22:36 -04:00
input
intc hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
ipack
ipmi
isa hw/isa/superio: Correct the license text 2020-04-01 19:00:16 +02:00
kvm
lm32
m68k
mem nvdimm: add uuid property to nvdimm 2020-02-21 09:15:04 +11:00
mips
misc hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
net hw/net: Add Smartfusion2 emac block 2020-04-30 11:52:28 +01:00
nubus
nvram fw_cfg: Migrate ACPI table mr sizes separately 2020-04-13 06:55:54 -04:00
pci pcie_root_port: Add hotplug disabling option 2020-03-08 09:18:29 -04:00
pci-bridge
pci-host hw/pci-host/q35: Remove unused includes 2020-03-09 15:59:31 +01:00
ppc ppc/pnv: Create BMC devices only when defaults are enabled 2020-04-07 08:55:11 +10:00
rdma
riscv hw/riscv: Add optional symbol callback ptr to riscv_load_firmware() 2020-04-29 13:16:38 -07:00
rtc hw/arm/allwinner: add RTC device support 2020-03-12 16:27:33 +00:00
s390x s390x/s390-virtio-ccw: Fix build on systems without KVM 2020-04-29 14:36:19 +02:00
scsi
sd hw/arm/allwinner: add SD/MMC host controller 2020-03-12 16:27:33 +00:00
semihosting
sh4
southbridge hw/ide: Do ide_drive_get() within pci_ide_create_devs() 2020-03-17 12:22:36 -04:00
sparc
ssi
timer
tricore
unicore32
usb hw/usb: Add basic i.MX USB Phy support 2020-03-17 11:23:14 +00:00
vfio
virtio fix vhost_user_blk_watch crash 2020-03-29 09:52:13 -04:00
watchdog
xen xen-bus/block: explicitly assign event channels to an AioContext 2020-02-27 11:50:30 +00:00
xtensa
boards.h vl/s390x: fixup ram sizes for compat machines 2020-04-02 17:10:09 +02:00
clock.h hw/core/clock-vmstate: define a vmstate entry for clock state 2020-04-30 15:35:40 +01:00
elf_ops.h elf_ops: Don't try to g_mapped_file_unref(NULL) 2020-05-04 14:35:23 +02:00
empty_slot.h
fw-path-provider.h
hotplug.h
hw.h
ide.h hw/ide: Move MAX_IDE_DEVS define to hw/ide/internal.h 2020-03-17 12:22:36 -04:00
irq.h
loader-fit.h
loader.h
nmi.h hw/nmi: Fix the NMI() macro, based on INTERFACE_CHECK() 2020-02-28 14:57:19 -05:00
or-irq.h
pcmcia.h
platform-bus.h
ptimer.h
qdev-clock.h qdev-clock: introduce an init array to ease the device construction 2020-04-30 15:35:40 +01:00
qdev-core.h qdev: add clock input&output support to devices. 2020-04-30 15:35:40 +01:00
qdev-dma.h
qdev-properties.h multifd: Add multifd-compression parameter 2020-02-28 09:24:43 +01:00
register.h
registerfields.h hw/registerfields.h: Add 8bit and 16bit register macros 2020-03-19 17:15:19 +01:00
resettable.h
stream.h
sysbus.h
usb.h
vmstate-if.h