From de71cc2389de2115be05805f00e06f2669358e04 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Tue, 21 Oct 2025 20:48:44 +0100 Subject: [PATCH] Prevent the use of any non-option arguments with -R or -Q (#101). --- src/main/options.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/options.c b/src/main/options.c index 792f100..4d1c199 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -1178,7 +1178,17 @@ opts_t opts_parse(unsigned int argc, char **argv) if (opts->error_skip_block > 0 && 0 == opts->skip_errors) opts->skip_errors = 1; - /* TODO: error if -Q given and there are any remaining arguments. */ + /* + * Don't allow any non-option arguments with -R or -Q. + */ + if ((optind < (int) argc) && ((0 != opts->remote) || (0 != opts->query))) { + /*@-mustfreefresh@ *//* see above */ + fprintf(stderr, "%s: %s: %s\n", opts->program_name, 0 != opts->remote ? "-R" : "-Q", + _("files cannot be specified with this option")); + opts_free(opts); + return NULL; + /*@+mustfreefresh@ */ + } /* * Store remaining command-line arguments.