Commit 2ff84aa2c95eba295e374f239b47e314d59e59cb

Authored by Dean Scarff
Committed by Jay Berkenbilt
1 parent 3fc7c99d

Include detailed OpenSSL error messages

Fixes qpdf/qpdf#450
Showing 1 changed file with 11 additions and 1 deletions
libqpdf/QPDFCrypto_openssl.cc
... ... @@ -2,6 +2,9 @@
2 2  
3 3 #include <cstring>
4 4 #include <stdexcept>
  5 +#include <string>
  6 +
  7 +#include <openssl/err.h>
5 8  
6 9 #include <qpdf/QIntC.hh>
7 10  
... ... @@ -18,8 +21,15 @@ check_openssl(int status)
18 21 {
19 22 if (status != 1)
20 23 {
21   - throw std::runtime_error("openssl error");
  24 + // OpenSSL creates a "queue" of errors; copy the first (innermost)
  25 + // error to the exception message.
  26 + char buf[256] = "";
  27 + ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
  28 + std::string what = "OpenSSL error: ";
  29 + what += buf;
  30 + throw std::runtime_error(what);
22 31 }
  32 + ERR_clear_error();
23 33 }
24 34  
25 35 QPDFCrypto_openssl::QPDFCrypto_openssl() :
... ...