From: Alexander Graf Date: Mon, 21 Nov 2011 11:04:07 +0000 (+0100) Subject: linux-user: fix QEMU_STRACE=1 segfault X-Git-Tag: v1.1-rc0~435^2~10 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=962b289ef35087fcd8764e4e29808d8ac90157f7;p=qemu.git linux-user: fix QEMU_STRACE=1 segfault While debugging some issues with QEMU_STRACE I stumbled over segmentation faults that were pretty reproducible. Turns out we tried to treat a normal return value as errno, resulting in an access over array boundaries for the resolution. Fix this by allowing failure to resolve invalid errnos into strings. Signed-off-by: Alexander Graf Signed-off-by: Riku Voipio --- diff --git a/linux-user/strace.c b/linux-user/strace.c index 90027a110..269481e7a 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -284,8 +284,13 @@ print_ipc(const struct syscallname *name, static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) { -if( ret == -1 ) { - gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno)); + char *errstr = NULL; + + if (ret == -1) { + errstr = target_strerror(errno); + } + if ((ret == -1) && errstr) { + gemu_log(" = -1 errno=%d (%s)\n", errno, errstr); } else { gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); } @@ -1515,14 +1520,19 @@ void print_syscall_ret(int num, abi_long ret) { int i; + char *errstr = NULL; for(i=0;i= ERRNO_TABLE_SIZE) || (err < 0)) { + return NULL; + } return strerror(target_to_host_errno(err)); }