aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-09-02 15:37:17 +0200
committerJay Berkenbilt <ejb@ql.org>2022-09-02 15:37:17 +0200
commit31396f61c98ff955118f192f75bf02320c7a2abc (patch)
tree037ef427d5537c588d13c9408c672597927ff6b9
parentfa15042ce9f95b69dcd1dc89449ff3b295b9eff3 (diff)
downloadqpdf-31396f61c98ff955118f192f75bf02320c7a2abc.tar.zst
Disallow --empty with --replace-input (fixes #728)
-rw-r--r--libqpdf/QPDFJob.cc8
-rw-r--r--qpdf/qtest/arg-parsing.test7
2 files changed, 14 insertions, 1 deletions
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index 691f193c..8bf619a2 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -683,7 +683,13 @@ QPDFJob::getExitCode() const
void
QPDFJob::checkConfiguration()
{
+ // Do final checks for command-line consistency. (I always think
+ // this is called doFinalChecks, so I'm putting that in a
+ // comment.)
+
if (m->replace_input) {
+ // Check for --empty appears later after we have checked
+ // m->infilename.
if (m->outfilename) {
usage("--replace-input may not be used when"
" an output file is specified");
@@ -700,6 +706,8 @@ QPDFJob::checkConfiguration()
}
if (m->infilename == nullptr) {
usage("an input file name is required");
+ } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) {
+ usage("--replace-input may not be used with --empty");
} else if (
m->require_outfile && (m->outfilename == nullptr) &&
(!m->replace_input)) {
diff --git a/qpdf/qtest/arg-parsing.test b/qpdf/qtest/arg-parsing.test
index 99c48b27..ad6bc0d2 100644
--- a/qpdf/qtest/arg-parsing.test
+++ b/qpdf/qtest/arg-parsing.test
@@ -15,7 +15,7 @@ cleanup();
my $td = new TestDriver('arg-parsing');
-my $n_tests = 16;
+my $n_tests = 17;
$td->runtest("required argument",
{$td->COMMAND => "qpdf --password minimal.pdf"},
@@ -102,6 +102,11 @@ $td->runtest("ignore -- at top level",
{$td->REGEXP => ".*No syntax or stream encoding errors found.*",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
+$td->runtest("empty and replace-input",
+ {$td->COMMAND => "qpdf --empty --replace-input"},
+ {$td->REGEXP => ".*--replace-input may not be used with --empty.*",
+ $td->EXIT_STATUS => 2},
+ $td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);