summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-11-07 13:10:44 -0500
committerTavian Barnes <tavianator@tavianator.com>2023-11-07 13:19:08 -0500
commit163baf1c9af13be0ce705b133e41e0c3d6427398 (patch)
tree64827684a24c345f436d1135b5b4fbe92933bd47 /src
parentce90dc9bc00c46b27b437467bb2f053ab2307fbc (diff)
downloadbfs-163baf1c9af13be0ce705b133e41e0c3d6427398.tar.xz
parse: Reject -{exec,ok}dir if $PATH contains a relative path
This matches the behaviour of GNU find.
Diffstat (limited to 'src')
-rw-r--r--src/parse.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c
index 09cfdd3..d21ab40 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -1263,6 +1263,28 @@ static struct bfs_expr *parse_exec(struct parser_state *state, int flags, int ar
expr->ephemeral_fds = 2;
if (execbuf->flags & BFS_EXEC_CHDIR) {
+ // Check for relative paths in $PATH
+ const char *path = getenv("PATH");
+ while (path) {
+ if (*path != '/') {
+ size_t len = strcspn(path, ":");
+ char *comp = strndup(path, len);
+ if (comp) {
+ parse_expr_error(state, expr,
+ "This action would be unsafe, since ${bld}$$PATH${rs} contains the relative path ${bld}%pq${rs}\n", comp);
+ free(comp);
+ } else {
+ parse_perror(state, "strndup()");
+ }
+ goto fail;
+ }
+
+ path = strchr(path, ':');
+ if (path) {
+ ++path;
+ }
+ }
+
// To dup() the parent directory
if (execbuf->flags & BFS_EXEC_MULTI) {
++expr->persistent_fds;
@@ -1276,6 +1298,10 @@ static struct bfs_expr *parse_exec(struct parser_state *state, int flags, int ar
}
return expr;
+
+fail:
+ bfs_expr_free(expr);
+ return NULL;
}
/**