From 2ff84aa2c95eba295e374f239b47e314d59e59cb Mon Sep 17 00:00:00 2001 From: Dean Scarff Date: Thu, 2 Jul 2020 12:40:33 +1000 Subject: [PATCH] Include detailed OpenSSL error messages Fixes qpdf/qpdf#450 --- libqpdf/QPDFCrypto_openssl.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libqpdf/QPDFCrypto_openssl.cc b/libqpdf/QPDFCrypto_openssl.cc index b1866b5d..358040d5 100644 --- a/libqpdf/QPDFCrypto_openssl.cc +++ b/libqpdf/QPDFCrypto_openssl.cc @@ -2,6 +2,9 @@ #include #include +#include + +#include #include @@ -18,8 +21,15 @@ check_openssl(int status) { if (status != 1) { - throw std::runtime_error("openssl error"); + // OpenSSL creates a "queue" of errors; copy the first (innermost) + // error to the exception message. + char buf[256] = ""; + ERR_error_string_n(ERR_get_error(), buf, sizeof(buf)); + std::string what = "OpenSSL error: "; + what += buf; + throw std::runtime_error(what); } + ERR_clear_error(); } QPDFCrypto_openssl::QPDFCrypto_openssl() :