about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-11-11 02:25:21 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-11-17 15:28:42 +0000
commitc392e6c620163b84798e705dfd6608d6429b9677 (patch)
tree25439f6a6c66cc2a183f0dbba3271d74c715d36f /Src/exec.c
parent0a6098a1d4debda1d57f4a7cd42bb5c49d65cddc (diff)
downloadzsh-c392e6c620163b84798e705dfd6608d6429b9677.tar.gz
zsh-c392e6c620163b84798e705dfd6608d6429b9677.tar.xz
zsh-c392e6c620163b84798e705dfd6608d6429b9677.zip
39915: whence: Honor PATH_DIRS option for arguments that start with './' or '../'.
While here, add some docstrings.
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Src/exec.c b/Src/exec.c
index a01a633db..ad80dd059 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -806,14 +806,13 @@ findcmd(char *arg0, int docopy, int default_path)
 	cn = hashcmd(arg0, path);
     if ((int) strlen(arg0) > PATH_MAX)
 	return NULL;
-    for (s = arg0; *s; s++)
-	if (*s == '/') {
-	    RET_IF_COM(arg0);
-	    if (arg0 == s || unset(PATHDIRS)) {
-		return NULL;
-	    }
-	    break;
+    if ((s = strchr(arg0, '/'))) {
+	RET_IF_COM(arg0);
+	if (arg0 == s || unset(PATHDIRS) || !strncmp(arg0, "./", 2) ||
+	    !strncmp(arg0, "../", 3)) {
+	    return NULL;
 	}
+    }
     if (cn) {
 	char nn[PATH_MAX];
 
@@ -848,6 +847,11 @@ findcmd(char *arg0, int docopy, int default_path)
     return NULL;
 }
 
+/*
+ * Return TRUE if the given path denotes an executable regular file, or a
+ * symlink to one.
+ */
+
 /**/
 int
 iscom(char *s)
@@ -877,6 +881,11 @@ isreallycom(Cmdnam cn)
     return iscom(fullnam);
 }
 
+/*
+ * Return TRUE if the given path contains a dot or dot-dot component
+ * and does not start with a slash.
+ */
+
 /**/
 int
 isrelative(char *s)