diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-04-07 06:51:32 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-04-07 06:51:32 +0000 |
commit | b9e686d81ebba316cf59b0590d47c61c81a06bfb (patch) | |
tree | 94d877fc249aafbb04dec039eeedd9ba9cf0581b | |
parent | 4b8eefc82d8bfb7decb554f8b07fce08da641a49 (diff) | |
download | glibc-b9e686d81ebba316cf59b0590d47c61c81a06bfb.zip glibc-b9e686d81ebba316cf59b0590d47c61c81a06bfb.tar.gz glibc-b9e686d81ebba316cf59b0590d47c61c81a06bfb.tar.bz2 |
(__getdents): The Linux kernel does not allow relative seeks on descriptors
associated with directories. Go back to get the position in the directory
every time we enter the function. Return -1 and set errno if one entry could
be read from the kernel but does not fit into the buffer passed in by the user.
-rw-r--r-- | sysdeps/unix/sysv/linux/getdents.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/sysdeps/unix/sysv/linux/getdents.c b/sysdeps/unix/sysv/linux/getdents.c index 9a2255c..d142843 100644 --- a/sysdeps/unix/sysv/linux/getdents.c +++ b/sysdeps/unix/sysv/linux/getdents.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2000 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 @@ -67,7 +67,7 @@ ssize_t internal_function __getdents (int fd, char *buf, size_t nbytes) { - off_t last_offset = 0; + off_t last_offset = __lseek (fd, 0, SEEK_CUR); size_t red_nbytes; struct kernel_dirent *skdp, *kdp; struct dirent *dp; @@ -96,13 +96,17 @@ __getdents (int fd, char *buf, size_t nbytes) if ((char *) dp + new_reclen > buf + nbytes) { /* Our heuristic failed. We read too many entries. Reset - the stream. `last_offset' contains the last known - position. If it is zero this is the first record we are - reading. In this case do a relative search. */ - if (last_offset == 0) - __lseek (fd, -retval, SEEK_CUR); - else - __lseek (fd, last_offset, SEEK_SET); + the stream. */ + __lseek (fd, last_offset, SEEK_SET); + + if ((char *) dp == buf) + { + /* The buffer the user passed in is too small to hold even + one entry. */ + __set_errno (EINVAL); + return -1; + } + break; } |