aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/opendir.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-08-27 16:54:04 +0000
committerUlrich Drepper <drepper@redhat.com>2003-08-27 16:54:04 +0000
commit45c24c06543eeb5eda07101aea5bb4488da9174a (patch)
tree50ebeccaf6e503f82ad938d5b4ffdfd1e9ddabe8 /sysdeps/unix/opendir.c
parent5556fc6ae42300e41a3c615a43def3e9da09094a (diff)
downloadglibc-45c24c06543eeb5eda07101aea5bb4488da9174a.tar
glibc-45c24c06543eeb5eda07101aea5bb4488da9174a.tar.gz
glibc-45c24c06543eeb5eda07101aea5bb4488da9174a.tar.bz2
glibc-45c24c06543eeb5eda07101aea5bb4488da9174a.zip
Update.
2003-08-27 Jakub Jelinek <jakub@redhat.com> * sysdeps/unix/opendir.c (__opendir): Make sure even struct dirent64 fits into allocation. Add padding on 32-bit arches so that dirp->data is enough aligned for struct dirent64. Avoid clearing of the buffer, just clear DIR structure.
Diffstat (limited to 'sysdeps/unix/opendir.c')
-rw-r--r--sysdeps/unix/opendir.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c
index 5e7c6e54a6..2938c67e4a 100644
--- a/sysdeps/unix/opendir.c
+++ b/sysdeps/unix/opendir.c
@@ -137,15 +137,17 @@ __opendir (const char *name)
goto lose;
#ifdef _STATBUF_ST_BLKSIZE
- if (__builtin_expect ((size_t) statbuf.st_blksize >= sizeof (struct dirent),
+ if (__builtin_expect ((size_t) statbuf.st_blksize >= sizeof (struct dirent64),
1))
allocation = statbuf.st_blksize;
else
#endif
- allocation = (BUFSIZ < sizeof (struct dirent)
- ? sizeof (struct dirent) : BUFSIZ);
+ allocation = (BUFSIZ < sizeof (struct dirent64)
+ ? sizeof (struct dirent64) : BUFSIZ);
- dirp = (DIR *) calloc (1, sizeof (DIR) + allocation); /* Zero-fill. */
+ const int pad = -sizeof (DIR) % __alignof__ (struct dirent64);
+
+ dirp = (DIR *) malloc (sizeof (DIR) + allocation + pad);
if (dirp == NULL)
lose:
{
@@ -154,7 +156,8 @@ __opendir (const char *name)
__set_errno (save_errno);
return NULL;
}
- dirp->data = (char *) (dirp + 1);
+ memset (dirp, '\0', sizeof (DIR));
+ dirp->data = (char *) (dirp + 1) + pad;
dirp->allocation = allocation;
dirp->fd = fd;