diff options
author | Jay Berkenbilt <ejb@ql.org> | 2023-12-23 02:09:31 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2023-12-23 02:10:21 +0100 |
commit | 1f4568684341ec3a0abb0c7ce72580b07b73d646 (patch) | |
tree | 652c54705bcf74b76a0923c11950f3a7e2c50cf6 | |
parent | a2c4a2b12a76bd932ba709d9c199a6f1684ba0be (diff) | |
download | qpdf-1f4568684341ec3a0abb0c7ce72580b07b73d646.tar.zst |
Handle --encrypt -- without crashing
-rw-r--r-- | libqpdf/QPDFJob_argv.cc | 1 | ||||
-rw-r--r-- | libqpdf/QPDFJob_config.cc | 3 | ||||
-rw-r--r-- | qpdf/qtest/arg-parsing.test | 7 |
3 files changed, 10 insertions, 1 deletions
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index 56acd7a9..3875474b 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -163,6 +163,7 @@ ArgParser::argShowCrypto() void ArgParser::argEncrypt() { + this->c_enc = c_main->encrypt(0, "", ""); this->accumulated_args.clear(); this->ap.selectOptionTable(O_ENCRYPTION); } diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 834de9ab..4798ce9b 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -1042,6 +1042,9 @@ QPDFJob::EncConfig::EncConfig(Config* c) : QPDFJob::Config* QPDFJob::EncConfig::endEncrypt() { + if (config->o.m->keylen == 0) { + usage("encryption key length is required"); + } config->o.m->encrypt = true; config->o.m->decrypt = false; config->o.m->copy_encryption = false; diff --git a/qpdf/qtest/arg-parsing.test b/qpdf/qtest/arg-parsing.test index 2f6bf621..aca8c7ef 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 = 21; +my $n_tests = 22; $td->runtest("required argument", {$td->COMMAND => "qpdf --password minimal.pdf"}, @@ -107,6 +107,11 @@ $td->runtest("empty and replace-input", {$td->REGEXP => ".*--replace-input may not be used with --empty.*", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("missing key length", + {$td->COMMAND => "qpdf --encrypt --"}, + {$td->REGEXP => ".*encryption key length is required", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); # Disallow mixing positional and flag-style encryption arguments. my @bad_enc = ( |