target/mips: Handle lock_user() failure in UHI_plog semihosting call
PATCH 1/1 target/mips: Handle lock_user() failure in UHI_plog semihosting call
Coverity notes that we forgot to check the error return from lock_user() in one place in the handling of the UHI_plog semihosting call. Add the missing error handling.
report_fault() is rather brutal in that it will call abort(), but this is the same error-handling used in the rest of this file.
Resolves: Coverity CID 1490684
---
NB: only tested with 'make check' and 'make check-tcg', which almost certainly don't actually exercise this codepath.
--- target/mips/tcg/sysemu/mips-semi.c | 3 +++ 1 file changed, 3 insertions(+)
target/mips/tcg/sysemu/mips-semi.c +3 -0
@@ -321,6 +321,9 @@ void mips_semihosting(CPUMIPSState *env)if (use_gdb_syscalls ()) { addr = gpr[29 ] - str->len; p =lock_user (VERIFY_WRITE , addr, str->len,0 ); +if (!p) { +report_fault (env); + }memcpy (p, str->str, str->len);unlock_user (p, addr, str->len);semihost_sys_write (cs, uhi_cb,2 , addr, str->len);
Signature · 1 line
2.25.1
Quoted 7 lines · Peter Maydell
Coverity notes that we forgot to check the error return from
lock_user()in one place in the handling of theUHI_plogsemihosting call. Add the missing error handling.
report_fault()is rather brutal in that it will callabort(), but this is the same error-handling used in the rest of this file.
Quoted 6 lines
Resolves: Coverity CID 1490684
Fixes ea4210600db3c5 ("target/mips: Avoid qemu_semihosting_log_out for UHI_plog")Signed-off-by Peter Maydell <[email protected]>---
NB: only tested with 'make check' and 'make check-tcg', which almost certainly don't actually exercise this codepath.
r~
Quoted 18 lines
--- target/mips/tcg/sysemu/mips-semi.c | 3 +++ 1 file changed, 3 insertions(+)target/mips/tcg/sysemu/mips-semi.c +3
-0@@ -321,6 +321,9 @@ void mips_semihosting(CPUMIPSState *env)if (use_gdb_syscalls ()) { addr = gpr[29 ] - str->len; p =lock_user (VERIFY_WRITE , addr, str->len,0 ); +if (!p) { +report_fault (env); + }memcpy (p, str->str, str->len);unlock_user (p, addr, str->len);semihost_sys_write (cs, uhi_cb,2 , addr, str->len);
Quoted 9 lines · Peter Maydell
Coverity notes that we forgot to check the error return from
lock_user()in one place in the handling of theUHI_plogsemihosting call. Add the missing error handling.
report_fault()is rather brutal in that it will callabort(), but this is the same error-handling used in the rest of this file.Resolves: Coverity CID 1490684
Quoted 8 lines
Fixes ea4210600db3c5 ("target/mips: Avoid qemu_semihosting_log_out for UHI_plog")Signed-off-by Peter Maydell <[email protected]>---
NB: only tested with 'make check' and 'make check-tcg', which almost certainly don't actually exercise this codepath.--- target/mips/tcg/sysemu/mips-semi.c | 3 +++ 1 file changed, 3 insertions(+)
Queued to mips-fixes, thanks!