aboutsummaryrefslogtreecommitdiff
path: root/mstat_plot.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2022-09-15 20:55:29 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2022-09-15 20:55:29 -0400
commit9478a7562e2780b4f9522c80f579153566308214 (patch)
tree725aabf6673d8820c0ae563d419f6b8132b97aa7 /mstat_plot.c
parent7971cc02be59a7d9115a8e436474433807588c6c (diff)
downloadmstat-9478a7562e2780b4f9522c80f579153566308214.tar.gz
find_program did not use the name argument all. robust.
Diffstat (limited to 'mstat_plot.c')
-rw-r--r--mstat_plot.c5
1 files changed, 4 insertions, 1 deletions
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;
}
}