* sysdeps/unix/opendir.c (__alloc_dir): If allocation fails for size

provided through st_blksize, try the default size before giving up.
This commit is contained in:
Ulrich Drepper 2008-03-30 08:51:55 +00:00
parent 43f6bec195
commit 221e523037
2 changed files with 25 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2008-03-30 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/opendir.c (__alloc_dir): If allocation fails for size
provided through st_blksize, try the default size before giving up.
2008-03-29 Ulrich Drepper <drepper@redhat.com> 2008-03-29 Ulrich Drepper <drepper@redhat.com>
* stdio-common/vfprintf.c (vfprintf): Correct overflow test. * stdio-common/vfprintf.c (vfprintf): Correct overflow test.

View File

@ -171,6 +171,8 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
goto lose; goto lose;
} }
const size_t default_allocation = (BUFSIZ < sizeof (struct dirent64)
? sizeof (struct dirent64) : BUFSIZ);
size_t allocation; size_t allocation;
#ifdef _STATBUF_ST_BLKSIZE #ifdef _STATBUF_ST_BLKSIZE
if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64), if (__builtin_expect ((size_t) statp->st_blksize >= sizeof (struct dirent64),
@ -178,11 +180,20 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
allocation = statp->st_blksize; allocation = statp->st_blksize;
else else
#endif #endif
allocation = (BUFSIZ < sizeof (struct dirent64) allocation = default_allocation;
? sizeof (struct dirent64) : BUFSIZ);
DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation); DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation);
if (dirp == NULL) if (dirp == NULL)
{
#ifdef _STATBUF_ST_BLKSIZE
if (allocation == statp->st_blksize
&& allocation != default_allocation)
{
allocation = default_allocation;
dirp = (DIR *) malloc (sizeof (DIR) + allocation);
}
if (dirp == NULL)
#endif
lose: lose:
{ {
if (close_fd) if (close_fd)
@ -193,6 +204,7 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
} }
return NULL; return NULL;
} }
}
dirp->fd = fd; dirp->fd = fd;
#ifndef NOT_IN_libc #ifndef NOT_IN_libc