From d9549b3d288a9cb053ab5198f3bc2d277b72600f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 18 Feb 2021 22:05:48 +0100 Subject: gensquashfs: always construct input path during option processing Signed-off-by: David Oberhollenzer --- bin/gensquashfs/options.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'bin/gensquashfs/options.c') diff --git a/bin/gensquashfs/options.c b/bin/gensquashfs/options.c index 9153265..ec2263c 100644 --- a/bin/gensquashfs/options.c +++ b/bin/gensquashfs/options.c @@ -267,7 +267,12 @@ void process_command_line(options_t *opt, int argc, char **argv) opt->infile = optarg; break; case 'D': - opt->packdir = optarg; + free(opt->packdir); + opt->packdir = strdup(optarg); + if (opt->packdir == NULL) { + perror(optarg); + exit(EXIT_FAILURE); + } break; #ifdef WITH_SELINUX case 's': @@ -316,8 +321,24 @@ void process_command_line(options_t *opt, int argc, char **argv) fputs("Unknown extra arguments specified.\n", stderr); goto fail_arg; } + + /* construct packdir if not specified */ + if (opt->packdir == NULL && opt->infile != NULL) { + const char *split = strrchr(opt->infile, '/'); + + if (split != NULL) { + opt->packdir = strndup(opt->infile, + split - opt->infile); + + if (opt->packdir == NULL) { + perror("constructing input directory path"); + exit(EXIT_FAILURE); + } + } + } return; fail_arg: fputs("Try `gensquashfs --help' for more information.\n", stderr); + free(opt->packdir); exit(EXIT_FAILURE); } -- cgit v1.2.3