From 02ebd9a0998917c6b60d8a9d16cd6430cdd8dc26 Mon Sep 17 00:00:00 2001 From: smitsohu Date: Wed, 21 Jul 2021 23:56:26 +0200 Subject: output options: expand ~ --- src/firejail/output.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/firejail/output.c b/src/firejail/output.c index 835dff2db..ce10ab157 100644 --- a/src/firejail/output.c +++ b/src/firejail/output.c @@ -50,13 +50,21 @@ void check_output(int argc, char **argv) { if (!outindex) return; - - // check filename drop_privs(0); char *outfile = argv[outindex]; outfile += (enable_stderr)? 16:9; + + // check filename invalid_filename(outfile, 0); // no globbing + // expand user home directory + if (outfile[0] == '~') { + char *full; + if (asprintf(&full, "%s%s", cfg.homedir, outfile + 1) == -1) + errExit("asprintf"); + outfile = full; + } + // do not accept directories, links, and files with ".." if (strstr(outfile, "..") || is_link(outfile) || is_dir(outfile)) { fprintf(stderr, "Error: invalid output file. Links, directories and files with \"..\" are not allowed.\n"); -- cgit v1.2.3-54-g00ecf