[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] linux-user: fix emulation of getdents
From: |
Dmitry V. Levin |
Subject: |
[Qemu-devel] [PATCH] linux-user: fix emulation of getdents |
Date: |
Fri, 17 Aug 2012 01:20:19 +0400 |
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 native dirent structure, thus breaking everything that relies
on valid d_type value, e.g. glob(3).
Signed-off-by: Dmitry V. Levin <address@hidden>
---
linux-user/syscall.c | 7 +++----
linux-user/syscall_defs.h | 3 ++-
2 files changed, 5 insertions(+), 5 deletions(-)
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 = 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..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 = NAME_MAX + '\0' + d_type */
};
struct target_dirent64 {
--
ldv
- [Qemu-devel] [PATCH] linux-user: fix emulation of getdents,
Dmitry V. Levin <=
- Re: [Qemu-devel] [PATCH] linux-user: fix emulation of getdents, Wei-Ren Chen, 2012/08/17
- Re: [Qemu-devel] [PATCH] linux-user: fix emulation of getdents, Blue Swirl, 2012/08/18
- [Qemu-devel] [PATCH v2] linux-user: fix emulation of getdents, Dmitry V. Levin, 2012/08/18
- Re: [Qemu-devel] [PATCH v2] linux-user: fix emulation of getdents, Blue Swirl, 2012/08/19
- Re: [Qemu-devel] [PATCH v2] linux-user: fix emulation of getdents, Peter Maydell, 2012/08/20
- [Qemu-devel] [PATCH v3] linux-user: fix emulation of getdents, Dmitry V. Levin, 2012/08/20
- Re: [Qemu-devel] [PATCH v3] linux-user: fix emulation of getdents, Peter Maydell, 2012/08/20
- Re: [Qemu-devel] [PATCH v4] linux-user: fix emulation of getdents, Dmitry V. Levin, 2012/08/20
- Re: [Qemu-devel] [PATCH v4] linux-user: fix emulation of getdents, Peter Maydell, 2012/08/21