diff options
author | 2012-02-04 23:02:40 +0000 | |
---|---|---|
committer | 2012-02-04 23:02:40 +0000 | |
commit | 6ca253dace519dec647e6538f12e568665236473 (patch) | |
tree | 4c585a06414a9455f38caeb72adfb48576fe31fb /lib/libc | |
parent | Close races where timer is started on a command and then an splbio() (diff) | |
download | wireguard-openbsd-6ca253dace519dec647e6538f12e568665236473.tar.xz wireguard-openbsd-6ca253dace519dec647e6538f12e568665236473.zip |
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')
-rw-r--r-- | lib/libc/gen/readdir.c | 13 |
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 |