Use an additional check with lstat(2) when d_type is unknown.

from James McDonald via portable.
This commit is contained in:
okan 2016-11-15 18:43:09 +00:00
parent db02592e5c
commit ae9f900b91

View File

@ -390,6 +390,7 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev)
struct screen_ctx *sc = ctx; struct screen_ctx *sc = ctx;
char **ap, *paths[NPATHS], *path, *pathcpy; char **ap, *paths[NPATHS], *path, *pathcpy;
char tpath[PATH_MAX]; char tpath[PATH_MAX];
struct stat sb;
const char *label; const char *label;
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
@ -426,14 +427,20 @@ kbfunc_menu_exec(void *ctx, union arg *arg, enum xev xev)
continue; continue;
while ((dp = readdir(dirp)) != NULL) { 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)); (void)memset(tpath, '\0', sizeof(tpath));
l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i], l = snprintf(tpath, sizeof(tpath), "%s/%s", paths[i],
dp->d_name); dp->d_name);
if (l == -1 || l >= sizeof(tpath)) if (l == -1 || l >= sizeof(tpath))
continue; 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) if (access(tpath, X_OK) == 0)
menuq_add(&menuq, NULL, "%s", dp->d_name); menuq_add(&menuq, NULL, "%s", dp->d_name);
} }