From patchwork Fri Feb 3 14:49:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 139402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 60599104792 for ; Sat, 4 Feb 2012 02:54:26 +1100 (EST) Received: from localhost ([::1]:41697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtKTf-0001fs-56 for incoming@patchwork.ozlabs.org; Fri, 03 Feb 2012 09:51:03 -0500 Received: from eggs.gnu.org ([140.186.70.92]:46226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtKSN-0007uD-C0 for qemu-devel@nongnu.org; Fri, 03 Feb 2012 09:49:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RtKSF-0001Uc-2C for qemu-devel@nongnu.org; Fri, 03 Feb 2012 09:49:43 -0500 Received: from afflict.kos.to ([92.243.29.197]:49804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RtKSE-0001Tc-PV for qemu-devel@nongnu.org; Fri, 03 Feb 2012 09:49:35 -0500 Received: by afflict.kos.to (Postfix, from userid 1000) id 6023126535; Fri, 3 Feb 2012 14:49:32 +0000 (UTC) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 3 Feb 2012 16:49:22 +0200 Message-Id: <962b289ef35087fcd8764e4e29808d8ac90157f7.1328280144.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 92.243.29.197 Cc: Alexander Graf Subject: [Qemu-devel] [PATCH 09/19] linux-user: fix QEMU_STRACE=1 segfault X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alexander Graf 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 --- linux-user/strace.c | 18 ++++++++++++++---- linux-user/syscall.c | 3 +++ 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= ERRNO_TABLE_SIZE) || (err < 0)) { + return NULL; + } return strerror(target_to_host_errno(err)); }