Commit 31396f61c98ff955118f192f75bf02320c7a2abc

Authored by Jay Berkenbilt
1 parent fa15042c

Disallow --empty with --replace-input (fixes #728)

libqpdf/QPDFJob.cc
... ... @@ -683,7 +683,13 @@ QPDFJob::getExitCode() const
683 683 void
684 684 QPDFJob::checkConfiguration()
685 685 {
  686 + // Do final checks for command-line consistency. (I always think
  687 + // this is called doFinalChecks, so I'm putting that in a
  688 + // comment.)
  689 +
686 690 if (m->replace_input) {
  691 + // Check for --empty appears later after we have checked
  692 + // m->infilename.
687 693 if (m->outfilename) {
688 694 usage("--replace-input may not be used when"
689 695 " an output file is specified");
... ... @@ -700,6 +706,8 @@ QPDFJob::checkConfiguration()
700 706 }
701 707 if (m->infilename == nullptr) {
702 708 usage("an input file name is required");
  709 + } else if (m->replace_input && (strlen(m->infilename.get()) == 0)) {
  710 + usage("--replace-input may not be used with --empty");
703 711 } else if (
704 712 m->require_outfile && (m->outfilename == nullptr) &&
705 713 (!m->replace_input)) {
... ...
qpdf/qtest/arg-parsing.test
... ... @@ -15,7 +15,7 @@ cleanup();
15 15  
16 16 my $td = new TestDriver('arg-parsing');
17 17  
18   -my $n_tests = 16;
  18 +my $n_tests = 17;
19 19  
20 20 $td->runtest("required argument",
21 21 {$td->COMMAND => "qpdf --password minimal.pdf"},
... ... @@ -102,6 +102,11 @@ $td->runtest("ignore -- at top level",
102 102 {$td->REGEXP => ".*No syntax or stream encoding errors found.*",
103 103 $td->EXIT_STATUS => 0},
104 104 $td->NORMALIZE_NEWLINES);
  105 +$td->runtest("empty and replace-input",
  106 + {$td->COMMAND => "qpdf --empty --replace-input"},
  107 + {$td->REGEXP => ".*--replace-input may not be used with --empty.*",
  108 + $td->EXIT_STATUS => 2},
  109 + $td->NORMALIZE_NEWLINES);
105 110  
106 111 cleanup();
107 112 $td->report($n_tests);
... ...