Package: cwm / 5.6-4

lstat-check Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From: James McDonald <james@jamesmcdonald.com>
Description: Fix 'exec' lookups for filesystems which don't support d_type.
 Lookups in kbfunc_exec fail on filesystems where the d_type field of
 struct dirent is not populated, such as XFS. This patch adds an additional
 test with lstat(2) if the initial test fails.
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -246,6 +246,7 @@
 	struct menu		*mi;
 	struct menu_q		 menuq;
 	int			 l, i, cmd = arg->i;
+	struct stat		sb;
 
 	switch (cmd) {
 	case CWM_EXEC_PROGRAM:
@@ -276,14 +277,19 @@
 			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) {
+				/* use an additional stat-based check in case d_type isn't supported */
+				if (lstat(tpath, &sb) < 0)
+					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);
 		}