Handle newlines better in sslerrorprinter.cpp

According to 4cedf30e99/crypto/err/err_prn.c (L20)
the ERR_print_errors_cb function already adds newlines to the end
of each line. So we can just append right away. We do remove the
last newline as normally error messages don't end with a newline.
Also we may return 0 instead of 1.
This commit is contained in:
Raoul Wols 2021-07-13 13:25:39 +02:00
parent 40d2af913e
commit 477243d3f3
No known key found for this signature in database
GPG Key ID: 9FFE06A0F6AAA2DF
1 changed files with 6 additions and 9 deletions

View File

@ -26,17 +26,11 @@ namespace AMQP {
*/
int sslerrorprintercallback(const char *str, size_t len, void *ctx)
{
// cast to ourselves
auto *self = static_cast<SslErrorPrinter*>(ctx);
// if this is not the first line, add a newline character
if (!self->_message.empty()) self->_message.push_back('\n');
// store the message
self->_message.append(str, len);
// Cast to ourselves and store the error line. OpenSSL adds a newline to every error line.
static_cast<SslErrorPrinter*>(ctx)->_message.append(str, len);
// continue with the next message
return 1;
return 0;
}
/**
@ -73,6 +67,9 @@ SslErrorPrinter::SslErrorPrinter(int retval)
// collect all error lines
OpenSSL::ERR_print_errors_cb(&sslerrorprintercallback, this);
// remove the last newline
if (!_message.empty() && _message.back() == '\n') _message.pop_back();
// done
break;