summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-04-03 23:51:40 -0700
committerPetr Baudis <pasky@ucw.cz>2010-05-12 03:21:07 +0200
commit043ea9e79d25398e8e0025b48444257e9e48029c (patch)
treeb5d7d75c541c95b92f6e6bfdf117a1603fa71056 /sysdeps
parentea614f680d5ede741bb2511364d190bceb9073b2 (diff)
Handle unnecessary padding in getdents64.
The getdents64 syscall adds on 32-but platforms padding which isn't needed and not included in the userlevel data structure definition. We have to avoid copying those padding bytes in the readdir64_r function. (cherry picked from commit 1a81139728494810f65aaa0d0c538ff8c2783dd5)
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/unix/readdir_r.c14
-rw-r--r--sysdeps/unix/sysv/linux/i386/readdir64_r.c3
2 files changed, 14 insertions, 3 deletions
diff --git a/sysdeps/unix/readdir_r.c b/sysdeps/unix/readdir_r.c
index f84709e737..93727912c1 100644
--- a/sysdeps/unix/readdir_r.c
+++ b/sysdeps/unix/readdir_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,02
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,02,10
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -113,7 +113,17 @@ __READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result)
while (dp->d_ino == 0);
if (dp != NULL)
- *result = memcpy (entry, dp, reclen);
+ {
+#ifdef GETDENTS_64BIT_ALIGNED
+ /* The d_reclen value might include padding which is not part of
+ the DIRENT_TYPE data structure. */
+ reclen = MIN (reclen, sizeof (DIRENT_TYPE));
+#endif
+ *result = memcpy (entry, dp, reclen);
+#ifdef GETDENTS_64BIT_ALIGNED
+ entry->d_reclen = reclen;
+#endif
+ }
else
*result = NULL;
diff --git a/sysdeps/unix/sysv/linux/i386/readdir64_r.c b/sysdeps/unix/sysv/linux/i386/readdir64_r.c
index c6da57b75e..f96f16a6f2 100644
--- a/sysdeps/unix/sysv/linux/i386/readdir64_r.c
+++ b/sysdeps/unix/sysv/linux/i386/readdir64_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2004, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,6 +19,7 @@
#define __READDIR_R __readdir64_r
#define __GETDENTS __getdents64
#define DIRENT_TYPE struct dirent64
+#define GETDENTS_64BIT_ALIGNED 1
#include <sysdeps/unix/readdir_r.c>