summary refs log tree commit diff
path: root/kbfunc.c
diff options
context:
space:
mode:
authorokan <okan>2016-11-15 18:43:09 +0000
committerokan <okan>2016-11-15 18:43:09 +0000
commitae9f900b91373f744fda7540cb42f281533fb7e4 (patch)
tree018cf36a6db475078f5dac162f80a662b7d9d2b1 /kbfunc.c
parentdb02592e5cfd5cf1395b4e40be8feb54f943a603 (diff)
downloadcwm-ae9f900b91373f744fda7540cb42f281533fb7e4.tar.gz
cwm-ae9f900b91373f744fda7540cb42f281533fb7e4.tar.xz
cwm-ae9f900b91373f744fda7540cb42f281533fb7e4.zip
Use an additional check with lstat(2) when d_type is unknown.
from James McDonald via portable.
Diffstat (limited to 'kbfunc.c')
-rw-r--r--kbfunc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/kbfunc.c b/kbfunc.c
index 8edea79..f0cadf2 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -390,6 +390,7 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev)
 	struct screen_ctx	*sc = ctx;
 	char			**ap, *paths[NPATHS], *path, *pathcpy;
 	char			 tpath[PATH_MAX];
+	struct stat		 sb;
 	const char		*label;
 	DIR			*dirp;
 	struct dirent		*dp;
@@ -426,14 +427,20 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev)
 			continue;
 
 		while ((dp = readdir(dirp)) != NULL) {
-			/* skip everything but regular files and symlinks */
-			if (dp->d_type != DT_REG && dp->d_type != DT_LNK)
-				continue;
 			(void)memset(tpath, '\0', sizeof(tpath));
 			l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i],
 			    dp->d_name);
 			if (l == -1 || l >= sizeof(tpath))
 				continue;
+			/* Skip everything but regular files and symlinks. */
+			if (dp->d_type != DT_REG && dp->d_type != DT_LNK) {
+				/* lstat(2) in case d_type isn't supported. */
+				if (lstat(tpath, &sb) == -1)
+					continue;
+				if (!S_ISREG(sb.st_mode) && 
+				    !S_ISLNK(sb.st_mode))
+					continue;
+			}
 			if (access(tpath, X_OK) == 0)
 				menuq_add(&menuq, NULL, "%s", dp->d_name);
 		}