From 7b11603935597aca382f93c462062801c4f87bfb Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 19 Jan 2010 17:12:44 +0000 Subject: Leave errno as-is if fstat(2) fails instead of masking the real errno with ENOTDIR. From Tim van der Molen. --- lib/libc/gen/opendir.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/libc/gen') diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 4028ba9c1eb..d7c60057f06 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opendir.c,v 1.19 2007/06/05 18:11:48 kurt Exp $ */ +/* $OpenBSD: opendir.c,v 1.20 2010/01/19 17:12:43 millert Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -62,7 +62,11 @@ __opendir2(const char *name, int flags) if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1) return (NULL); - if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) { + if (fstat(fd, &sb)) { + close(fd); + return (NULL); + } + if (!S_ISDIR(sb.st_mode)) { close(fd); errno = ENOTDIR; return (NULL); @@ -89,7 +93,7 @@ __opendir2(const char *name, int flags) dirp->dd_buf = malloc((size_t)dirp->dd_len); if (dirp->dd_buf == NULL) { free(dirp); - close (fd); + close(fd); return (NULL); } -- cgit v1.2.3