Received: from eggs.gnu.org ([208.118.235.92]:56091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2H3W-0007TE-3b for qemu-devel@nongnu.org; Fri, 17 Aug 2012 03:33:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T2H3S-0001Rm-Mj for qemu-devel@nongnu.org; Fri, 17 Aug 2012 03:33:18 -0400 Received: from csmailer.cs.nctu.edu.tw ([140.113.235.130]:10061) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2H3S-0001RP-02 for qemu-devel@nongnu.org; Fri, 17 Aug 2012 03:33:14 -0400 Date: Fri, 17 Aug 2012 15:33:04 +0800 From: =?utf-8?B?6Zmz6Z+L5Lu7IChXZWktUmVuIENoZW4p?= Message-ID: <20120817073304.GA64092@cs.nctu.edu.tw> References: <20120816212019.GB3688@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20120816212019.GB3688@altlinux.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] linux-user: fix emulation of getdents List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Riku Voipio CC'ed to linux-user maintainer, Riku. On Fri, Aug 17, 2012 at 01:20:19AM +0400, Dmitry V. Levin wrote: > In case when TARGET_ABI_BITS =3D=3D 32 && HOST_LONG_BITS =3D=3D 64, the= last > byte of the target dirent structure (aka d_type byte) was never copied > from the native dirent structure, thus breaking everything that relies > on valid d_type value, e.g. glob(3). >=20 > Signed-off-by: Dmitry V. Levin > --- > linux-user/syscall.c | 7 +++---- > linux-user/syscall_defs.h | 3 ++- > 2 files changed, 5 insertions(+), 5 deletions(-) >=20 > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 41c869b..2b6025b 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -7030,10 +7030,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_= long arg1, > tde->d_ino =3D tswapal(de->d_ino); > tde->d_off =3D tswapal(de->d_off); > tnamelen =3D treclen - (2 * sizeof(abi_long) + 2); > - if (tnamelen > 256) > - tnamelen =3D 256; > - /* XXX: may not be correct */ > - pstrcpy(tde->d_name, tnamelen, de->d_name); > + if (tnamelen > sizeof(tde->d_name)) > + tnamelen =3D sizeof(tde->d_name); > + memcpy(tde->d_name, de->d_name, tnamelen); > de =3D (struct linux_dirent *)((char *)de + reclen= ); > len -=3D reclen; > tde =3D (struct target_dirent *)((char *)tde + tre= clen); > diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h > index 2cfda5a..f27a8d4 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]; /* We must not include limits.h! */ > + /* 257 =3D NAME_MAX + '\0' + d_type */ > }; > =20 > struct target_dirent64 { >=20 > --=20 > ldv --=20 Wei-Ren Chen (=E9=99=B3=E9=9F=8B=E4=BB=BB) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj