From 353cbdc9ebccfc8313a8cb59d0121d3a3fb5d5b2 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 22 Jan 2026 21:07:10 +0100 Subject: [PATCH] bin: allow 'copy foo' for shell users With guard rails in CLI, without in shell. Signed-off-by: Joachim Wiberg --- src/bin/util.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bin/util.c b/src/bin/util.c index f922f484..1226c3a6 100644 --- a/src/bin/util.c +++ b/src/bin/util.c @@ -129,14 +129,19 @@ char *cfg_adjust(const char *path, const char *template, bool sanitize) if (!path_allowed(path)) goto err; } + + /* CLI users save to /cfg by default, unless abs. path */ + if (asprintf(&expanded, "%s%.*s/%s%s", + path[0] == '/' ? "" : "/cfg/", + dlen, path, + basename, + strchr(basename, '.') ? "" : ".cfg") < 0) + goto err; + } else { + /* Shell users expect copy to behave more like cp */ + expanded = strdup(path); } - if (asprintf(&expanded, "%s%.*s/%s%s", - path[0] == '/' ? "" : "/cfg/", - dlen, path, - basename, - strchr(basename, '.') ? "" : ".cfg") < 0) - goto err; if (sanitize) { resolved = realpath(expanded, NULL);