diff --git a/usr.sbin/sysinst/util.c b/usr.sbin/sysinst/util.c index 1ec00de47b3c..fbb2cd35e52a 100644 --- a/usr.sbin/sysinst/util.c +++ b/usr.sbin/sysinst/util.c @@ -1681,14 +1681,16 @@ set_menu_select(menudesc *m, void *arg) int binary_available(const char *prog) { - char *p, tmp[MAXPATHLEN], *path = getenv("PATH"); + char *p, tmp[MAXPATHLEN], *path = getenv("PATH"), *opath; if (path == NULL) return access(prog, X_OK) == 0; path = strdup(path); if (path == NULL) return 0; - + + opath = path; + while ((p = strsep(&path, ":")) != NULL) { if (strlcpy(tmp, p, MAXPATHLEN) >= MAXPATHLEN) continue; @@ -1697,11 +1699,11 @@ binary_available(const char *prog) if (strlcat(tmp, prog, MAXPATHLEN) >= MAXPATHLEN) continue; if (access(tmp, X_OK) == 0) { - free(path); + free(opath); return 1; } } - free(path); + free(opath); return 0; }