summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-02-04 23:02:41 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-02-04 23:02:41 +0000
commit53fd6962b5a83a231bbd28faa1ed1607ea6ef75e (patch)
tree711ae4a3e885e19300e9d745f77c19d8c418c7aa /lib/libc/gen
parenta18d78fa5c6e118934514091c938a5aa2524695d (diff)
If the internal consistency check fails, set errno so that it doesn't
just look like end-of-directory. ok krw@ otto@ miod@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/readdir.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index f4262573b13..bbf178b0c42 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readdir.c,v 1.15 2009/11/18 07:43:22 guenther Exp $ */
+/* $OpenBSD: readdir.c,v 1.16 2012/02/04 23:02:40 guenther Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -29,6 +29,7 @@
*/
#include <dirent.h>
+#include <errno.h>
#include "thread_private.h"
/*
@@ -52,12 +53,14 @@ _readdir_unlocked(DIR *dirp, struct dirent **result, int skipdeleted)
return (-1);
}
dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
- if ((long)dp & 03) /* bogus pointer check */
- return (-1);
- if (dp->d_reclen <= 0 ||
- dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc)
+ if ((long)dp & 03 || /* bogus pointer check */
+ dp->d_reclen <= 0 ||
+ dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) {
+ errno = EINVAL;
return (-1);
+ }
dirp->dd_loc += dp->d_reclen;
+
/*
* When called from seekdir(), we let it decide on
* the end condition to avoid overshooting: the next