aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2016-11-15 18:43:09 +0000
committerokan2016-11-15 18:43:09 +0000
commit7d7ddd83d0ef8a1e13ad804285921353c69a8e0f (patch)
tree6cced2abc172606cde83cac3130cb8ddf7ae1d6b
parentfa650aaea211350bbeb9723e3e8749c61ce5bcac (diff)
downloadcwm-7d7ddd83d0ef8a1e13ad804285921353c69a8e0f.tar.gz
Use an additional check with lstat(2) when d_type is unknown.
from James McDonald via portable.
Diffstat (limited to '')
-rw-r--r--kbfunc.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/kbfunc.c b/kbfunc.c
index f682452..6c4aa9a 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: kbfunc.c,v 1.136 2016/11/15 00:22:02 okan Exp $
+ * $OpenBSD: kbfunc.c,v 1.137 2016/11/15 18:43:09 okan Exp $
*/
#include <sys/types.h>
@@ -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);
}