search_for_executable() fails to process last part of PATH if PATH does not end with ':'
authorJingyi Hou <houjingyi@gmail.com>
Thu, 23 May 2013 18:18:23 +0000 (02:18 +0800)
committerChristophe Rhodes <csr21@cantab.net>
Thu, 23 May 2013 19:47:37 +0000 (20:47 +0100)
src/runtime/runtime.c

index 49c007b..cacc9c7 100644 (file)
@@ -287,6 +287,18 @@ search_for_executable(const char *argv0)
             return search;
         }
     }
+    /* The above for-loop fails to process the last part of PATH if PATH does
+     * not end with ':'. We may consider appending an extra ':' to the end of
+     * SEARCH.  -- houjingyi 2013-05-24 */
+    if (start != NULL && *start != '\0') {
+        snprintf(buf, PATH_MAX + 1, "%s/%s", start, argv0);
+        if (access(buf, F_OK) == 0) {
+            free(search);
+            search = copied_realpath(buf);
+            free(buf);
+            return search;
+        }
+    }
 
     free(search);
     free(buf);