summaryrefslogtreecommitdiff
path: root/usr.bin/mg/dired.c
diff options
context:
space:
mode:
authorChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2012-11-03 15:36:04 +0000
committerChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2012-11-03 15:36:04 +0000
commit98870c98aad8e7635f9b7769ac8b3d2a0f6a421c (patch)
tree7cc2f4442c70d0c1bac48f6bf1aaa8b83c53eaf5 /usr.bin/mg/dired.c
parentfc2afa2187c47c08797529c4ef6a0070ac0e3d27 (diff)
Don't leak a file descriptor when testing for permissions, also make
sure directory is executable, otherwise we can't list it. Found by and original diff from RustyBSD. While here, strlen returns a size_t not an int. ok florian.
Diffstat (limited to 'usr.bin/mg/dired.c')
-rw-r--r--usr.bin/mg/dired.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index 184c9f7de4b..8630f2ec49d 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.51 2012/03/14 13:56:35 lum Exp $ */
+/* $OpenBSD: dired.c,v 1.52 2012/11/03 15:36:03 haesbaert Exp $ */
/* This file is in the public domain. */
@@ -724,9 +724,10 @@ struct buffer *
dired_(char *dname)
{
struct buffer *bp;
- int len, i;
+ int i;
+ size_t len;
- if ((fopen(dname,"r")) == NULL) {
+ if ((access(dname, R_OK | X_OK)) == -1) {
if (errno == EACCES)
ewprintf("Permission denied");
return (NULL);