public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix opendir
@ 2003-08-27 16:39 Jakub Jelinek
  2003-08-27 16:57 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2003-08-27 16:39 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix opendir
  2003-08-27 16:39 [PATCH] Fix opendir Jakub Jelinek
@ 2003-08-27 16:57 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2003-08-27 16:57 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jakub Jelinek wrote:

> readdir/readdir64 assume dirp->data is aligned enough for struct dirent64,
> which on 32-bit NPTL arches is not true.

Applied, thanks.


> 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)?

Theoretically yes.  But I haven't seen any need for this so far.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/TOLp2ijCOnn/RHQRAmpBAJ0drEmGqHUdNk/AtD3SuHaK79hmEQCcDHxy
MZwT60d1OBV3KMPjqO7bFgc=
=DJPf
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-27 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-27 16:39 [PATCH] Fix opendir Jakub Jelinek
2003-08-27 16:57 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).