hw/mips/malta: Silence warning from ubsan
PATCH 1/1 hw/mips/malta: Silence warning from ubsan
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when using the malta machine:
hw/mips/malta.c:1200:32: runtime error: addition of unsigned offset
to 0x7fb620600000 overflowed to 0x7fb6205fffff
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior hw/mips/malta.c:1200:32
To fix the issue, check the bios_size whether we really loaded the firmware before trying to byte-swap the instructions here.
--- hw/mips/malta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mips/malta.c +1 -1
@@ -1190,7 +1190,7 @@ void mips_malta_init(MachineState *machine)* In little endian mode the 32bit words in the bios are swapped, * a neat trick which allows bi-endian firmware. */ -if (!TARGET_BIG_ENDIAN ) { +if (!TARGET_BIG_ENDIAN && bios_size >0 ) {uint32_t *end, *addr;const size_t swapsize =MIN (bios_size,0x3e0000 ); addr =rom_ptr (FLASH_ADDRESS , swapsize);
Signature · 1 line
2.50.1
Hi Thomas,
Quoted 22 lines · Thomas Huth
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when using the malta machine:
hw/mips/malta.c:1200:32: runtime error: addition of unsigned offset
to0x7fb620600000overflowed to0x7fb6205fffff
SUMMARY: UndefinedBehaviorSanitizer: undefined-behaviorhw/mips/malta.c:1200:32To fix the issue, check the
bios_sizewhether we really loaded the firmware before trying to byte-swap the instructions here.Signed-off-by Thomas Huth <[email protected]>--- hw/mips/malta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/mips/malta.c +0
-0
hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1196
Quoted 8 lines
hw/mips/malta.c +1
-1@@ -1190,7 +1190,7 @@ void mips_malta_init(MachineState *machine)* In little endian mode the 32bit words in the bios are swapped, * a neat trick which allows bi-endian firmware. */ -if (!TARGET_BIG_ENDIAN ) { +if (!TARGET_BIG_ENDIAN && bios_size >0 ) {uint32_t *end, *addr;const size_t swapsize =MIN (bios_size,0x3e0000 ); addr =rom_ptr (FLASH_ADDRESS , swapsize);
What about:
-- >8 --
@@ -1180,7 +1180,7 @@ void mips_malta_init(MachineState *machine)
} else {
bios_size = -1;
}
- if ((bios_size < 0 || bios_size > BIOS_SIZE) &&
+ if ((bios_size <= 0 || bios_size > BIOS_SIZE) &&
machine->firmware && !qtest_enabled()) {
error_report("Could not load MIPS bios '%s'",
machine->firmware);
exit(1);---
?
Philippe Mathieu-Daudé
Reviewed-byQuoted 20 lines · Philippe Mathieu-Daudé
Hi Thomas,
Quoted 17 lines · Thomas Huth
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when using the malta machine:
hw/mips/malta.c:1200:32: runtime error: addition of unsigned offset to0x7fb620600000overflowed to0x7fb6205fffff
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior hw/mips/ malta.c:1200:32To fix the issue, check the
bios_sizewhether we really loaded the firmware before trying to byte-swap the instructions here.Signed-off-by Thomas Huth <[email protected]>---
hw/mips/malta.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
hw/mips/malta.c void mips_malta_init(MachineState *machine) · line 1196
Quoted 13 lines
hw/mips/malta.c +1
-1@@ -1190,7 +1190,7 @@ void mips_malta_init(MachineState *machine)* In little endian mode the 32bit words in the bios are swapped, * a neat trick which allows bi-endian firmware. */ - if (!TARGET_BIG_ENDIAN) { + if (!TARGET_BIG_ENDIAN && bios_size > 0) { uint32_t *end, *addr; const size_t swapsize = MIN(bios_size, 0x3e0000); addr = rom_ptr(FLASH_ADDRESS, swapsize);
and queued, thanks!
Quoted 17 lines
What about:
-- >8 --
(quoted diff) +1
-1@@ -1180,7 +1180,7 @@ void mips_malta_init(MachineState *machine) } else { bios_size = -1; } - if ((bios_size < 0 || bios_size > BIOS_SIZE) && + if ((bios_size <= 0 || bios_size > BIOS_SIZE) && machine->firmware && !qtest_enabled()) { error_report("Could not load MIPS bios '%s'", machine- >firmware);exit(1);
---?