From 9478a7562e2780b4f9522c80f579153566308214 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 15 Sep 2022 20:55:29 -0400 Subject: find_program did not use the name argument all. robust. --- mstat_plot.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mstat_plot.c') diff --git a/mstat_plot.c b/mstat_plot.c index e264d63..e846c61 100644 --- a/mstat_plot.c +++ b/mstat_plot.c @@ -38,14 +38,17 @@ static int find_program(const char *name) { char *path; char *pathtmp; char *token; + char pathtest[PATH_MAX] = {0}; pathtmp = getenv("PATH"); if (!pathtmp) { return 1; } path = strdup(pathtmp); + while ((token = strsep(&path, ":")) != NULL) { - if (access(token, F_OK | X_OK) == 0) { + snprintf(pathtest, PATH_MAX - 1, "%s/%s", token, name); + if (access(pathtest, F_OK | X_OK) == 0) { return 0; } } -- cgit