From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T356U-0002TY-Pj for qemu-devel@nongnu.org; Sun, 19 Aug 2012 08:59:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T356T-0002RA-Jj for qemu-devel@nongnu.org; Sun, 19 Aug 2012 08:59:42 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:44920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T356T-0002R6-D0 for qemu-devel@nongnu.org; Sun, 19 Aug 2012 08:59:41 -0400 Received: by obbta14 with SMTP id ta14so7725586obb.4 for ; Sun, 19 Aug 2012 05:59:40 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20120818215629.GA27951@altlinux.org> References: <20120816212019.GB3688@altlinux.org> <20120818215629.GA27951@altlinux.org> From: Blue Swirl Date: Sun, 19 Aug 2012 12:59:19 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v2] linux-user: fix emulation of getdents List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dmitry V. Levin" Cc: Riku Voipio , qemu-devel@nongnu.org On Sat, Aug 18, 2012 at 9:56 PM, Dmitry V. Levin wrote: > 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). > > Signed-off-by: Dmitry V. Levin Acked-by: Blue Swirl > --- > linux-user/syscall.c | 8 ++++---- > linux-user/syscall_defs.h | 3 ++- > 2 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 41c869b..adc3270 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -7030,10 +7030,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > 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); > + if (tnamelen > sizeof(tde->d_name)) { > + tnamelen = sizeof(tde->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..19fe414 100644 > --- a/linux-user/syscall_defs.h > +++ b/linux-user/syscall_defs.h > @@ -258,7 +258,8 @@ 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! */ > + char d_name[257]; /* 257 = NAME_MAX + '\0' + d_type, */ > + /* we must not include limits.h! */ > }; > > struct target_dirent64 { > > -- > ldv