Skip to content

Commit

Permalink
Handle unnecessary padding in getdents64.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ulrich Drepper committed Apr 4, 2010
1 parent 3fedf0f commit 1a81139
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
2010-04-03 Ulrich Drepper <drepper@redhat.com>

[BZ #11333]
* sysdeps/unix/readdir_r.c (__READDIR_R): Add support for platforms
which include unnecessary padding in d_reclen.
* sysdeps/unix/sysv/linux/i386/readdir64_r.c: Select work-around for
unnecessary padding.

[BZ #11387]
* sysdeps/unix/sysv/linux/ifaddrs.c (map_newlin): Don't abort on
unknown interface, return -1.
Expand Down
14 changes: 12 additions & 2 deletions sysdeps/unix/readdir_r.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion sysdeps/unix/sysv/linux/i386/readdir64_r.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>

Expand Down

0 comments on commit 1a81139

Please sign in to comment.