Commit 6e2a07e1dfe4281ad68825115f69980c1011d20a

Authored by m-holger
1 parent 7475b353

In QPDFJob refactor password handling to use std::string instead of shared_ptr.

Replaced `std::shared_ptr<char>` with `std::string` for password fields to simplify memory management and improve clarity. Updated relevant method implementations and function calls accordingly. This change ensures more straightforward and safer password handling throughout the codebase.
include/qpdf/QPDFJob.hh
... ... @@ -591,7 +591,7 @@ class QPDFJob
591 591 bool warnings{false};
592 592 unsigned long encryption_status{0};
593 593 bool verbose{false};
594   - std::shared_ptr<char> password;
  594 + std::string password;
595 595 bool linearize{false};
596 596 bool decrypt{false};
597 597 bool remove_restrictions{false};
... ... @@ -602,7 +602,7 @@ class QPDFJob
602 602 bool warnings_exit_zero{false};
603 603 bool copy_encryption{false};
604 604 std::string encryption_file;
605   - std::shared_ptr<char> encryption_file_password;
  605 + std::string encryption_file_password;
606 606 bool encrypt{false};
607 607 bool password_is_hex_key{false};
608 608 bool suppress_password_recovery{false};
... ...
libqpdf/QPDFJob.cc
... ... @@ -440,7 +440,7 @@ QPDFJob::createQPDF()
440 440 checkConfiguration();
441 441 std::unique_ptr<QPDF> pdf_sp;
442 442 try {
443   - processFile(pdf_sp, m->infilename.data(), m->password.get(), true, true);
  443 + processFile(pdf_sp, m->infilename.data(), m->password.data(), true, true);
444 444 } catch (QPDFExc& e) {
445 445 if (e.getErrorCode() == qpdf_e_password) {
446 446 // Allow certain operations to work when an incorrect password is supplied.
... ... @@ -2471,10 +2471,10 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2471 2471 // different QPDF objects to the same underlying file with the same path to achieve the
2472 2472 // same effect.
2473 2473 char const* password = page_spec.password.get();
2474   - if ((!m->encryption_file.empty()) && (password == nullptr) &&
2475   - (page_spec.filename == m->encryption_file)) {
  2474 + if (!m->encryption_file.empty() && password == nullptr &&
  2475 + page_spec.filename == m->encryption_file) {
2476 2476 QTC::TC("qpdf", "QPDFJob pages encryption password");
2477   - password = m->encryption_file_password.get();
  2477 + password = m->encryption_file_password.data();
2478 2478 }
2479 2479 doIfVerbose([&](Pipeline& v, std::string const& prefix) {
2480 2480 v << prefix << ": processing " << page_spec.filename << "\n";
... ... @@ -2962,8 +2962,8 @@ QPDFJob::setWriterOptions(QPDFWriter&amp; w)
2962 2962 std::unique_ptr<QPDF> encryption_pdf;
2963 2963 processFile(
2964 2964 encryption_pdf,
2965   - m->encryption_file.c_str(),
2966   - m->encryption_file_password.get(),
  2965 + m->encryption_file.data(),
  2966 + m->encryption_file_password.data(),
2967 2967 false,
2968 2968 false);
2969 2969 w.copyEncryptionParameters(*encryption_pdf);
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -175,7 +175,7 @@ QPDFJob::Config::deterministicId()
175 175 QPDFJob::Config*
176 176 QPDFJob::Config::encryptionFilePassword(std::string const& parameter)
177 177 {
178   - o.m->encryption_file_password = QUtil::make_shared_cstr(parameter);
  178 + o.m->encryption_file_password = parameter;
179 179 return this;
180 180 }
181 181  
... ... @@ -456,7 +456,7 @@ QPDFJob::Config::optimizeImages()
456 456 QPDFJob::Config*
457 457 QPDFJob::Config::password(std::string const& parameter)
458 458 {
459   - o.m->password = QUtil::make_shared_cstr(parameter);
  459 + o.m->password = parameter;
460 460 return this;
461 461 }
462 462  
... ... @@ -697,7 +697,7 @@ QPDFJob::Config::passwordFile(std::string const&amp; parameter)
697 697 lines = QUtil::read_lines_from_file(parameter.c_str());
698 698 }
699 699 if (!lines.empty()) {
700   - o.m->password = QUtil::make_shared_cstr(lines.front());
  700 + o.m->password = lines.front();
701 701  
702 702 if (lines.size() > 1) {
703 703 *QPDFLogger::defaultLogger()->getError()
... ...