This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi! readdir/readdir64 assume dirp->data is aligned enough for struct dirent64, which on 32-bit NPTL arches is not true. Unrelated question: seekdir/telldir work with long int offset instead of off_t/off64_t. Shouldn't there be new API like ftello/fseeko (seekdiro/telldiro/seekdiro64/telldiro64)? 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. --- libc/sysdeps/unix/opendir.c.jj Tue Jul 15 03:03:04 2003 +++ libc/sysdeps/unix/opendir.c Wed Aug 27 16:01:05 2003 @@ -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; Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |