From patchwork Mon Aug 27 18:22:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 180260 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7D78A2C00F6 for ; Tue, 28 Aug 2012 04:23:04 +1000 (EST) Received: from localhost ([::1]:34969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T63xm-0008K1-4d for incoming@patchwork.ozlabs.org; Mon, 27 Aug 2012 14:23:02 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T63xZ-0008Ja-0V for qemu-devel@nongnu.org; Mon, 27 Aug 2012 14:22:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T63xX-0004D0-ER for qemu-devel@nongnu.org; Mon, 27 Aug 2012 14:22:48 -0400 Received: from afflict.kos.to ([92.243.29.197]:33821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T63xX-0004Cm-6w for qemu-devel@nongnu.org; Mon, 27 Aug 2012 14:22:47 -0400 Received: from kos.to (a91-156-57-9.elisa-laajakaista.fi [91.156.57.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 72F36264D1 for ; Mon, 27 Aug 2012 20:22:45 +0200 (CEST) Received: from voipio (uid 1000) (envelope-from voipio@kos.to) id 5e01cc by kos.to (DragonFly Mail Agent); Mon, 27 Aug 2012 21:22:44 +0300 From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 27 Aug 2012 21:22:42 +0300 Message-Id: <333858b77c2b4f7636257808a77822c58bdd80fe.1346088997.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 92.243.29.197 Cc: "Dmitry V. Levin" Subject: [Qemu-devel] [PATCH 2/3] linux-user: fix emulation of getdents 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: "Dmitry V. Levin" In case when TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64, the last byte of the target dirent structure (aka d_type byte) was never copied from the host dirent structure, thus breaking everything that relies on valid d_type value, e.g. glob(3). Reviewed-by: Peter Maydell Signed-off-by: Dmitry V. Levin Signed-off-by: Riku Voipio --- linux-user/syscall.c | 11 +++++------ linux-user/syscall_defs.h | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1174306..6257a04 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7025,15 +7025,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, tde = target_dirp; while (len > 0) { reclen = de->d_reclen; - treclen = reclen - (2 * (sizeof(long) - sizeof(abi_long))); + tnamelen = reclen - offsetof(struct linux_dirent, d_name); + assert(tnamelen >= 0); + treclen = tnamelen + offsetof(struct target_dirent, d_name); + assert(count1 + treclen <= count); tde->d_reclen = tswap16(treclen); tde->d_ino = tswapal(de->d_ino); tde->d_off = tswapal(de->d_off); - tnamelen = treclen - (2 * sizeof(abi_long) + 2); - if (tnamelen > 256) - tnamelen = 256; - /* XXX: may not be correct */ - pstrcpy(tde->d_name, tnamelen, de->d_name); + memcpy(tde->d_name, de->d_name, tnamelen); de = (struct linux_dirent *)((char *)de + reclen); len -= reclen; tde = (struct target_dirent *)((char *)tde + treclen); diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 2cfda5a..a98cbf7 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -255,10 +255,10 @@ struct kernel_statfs { }; struct target_dirent { - abi_long d_ino; - abi_long d_off; - unsigned short d_reclen; - char d_name[256]; /* We must not include limits.h! */ + abi_long d_ino; + abi_long d_off; + unsigned short d_reclen; + char d_name[]; }; struct target_dirent64 {