aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2011-11-21 12:04:07 +0100
committerRiku Voipio <riku.voipio@linaro.org>2012-02-02 17:51:20 +0200
commit962b289ef35087fcd8764e4e29808d8ac90157f7 (patch)
tree01641e19658a15ae9861350a18273b580c0faccc /linux-user
parent583359a68922fb91b793a5ad3a2dd4536bf9b99e (diff)
downloadqemu-962b289ef35087fcd8764e4e29808d8ac90157f7.zip
qemu-962b289ef35087fcd8764e4e29808d8ac90157f7.tar.gz
qemu-962b289ef35087fcd8764e4e29808d8ac90157f7.tar.bz2
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 <agraf@suse.de> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/strace.c18
-rw-r--r--linux-user/syscall.c3
2 files changed, 17 insertions, 4 deletions
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 90027a1..269481e 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<nsyscalls;i++)
if( scnames[i].nr == num ) {
if( scnames[i].result != NULL ) {
scnames[i].result(&scnames[i],ret);
} else {
- if( ret < 0 ) {
- gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, target_strerror(-ret));
+ if (ret < 0) {
+ errstr = target_strerror(-ret);
+ }
+ if (errstr) {
+ gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
+ -ret, errstr);
} else {
gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 15b8b22..29d92c4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -731,6 +731,9 @@ static inline int is_error(abi_long ret)
char *target_strerror(int err)
{
+ if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) {
+ return NULL;
+ }
return strerror(target_to_host_errno(err));
}