Simplify error queue macros

This commit is contained in:
Juliusz Sosinowicz
2021-12-16 12:39:58 +01:00
parent e78f7f734e
commit 017d6cf464
3 changed files with 73 additions and 34 deletions

View File

@@ -17686,6 +17686,7 @@ cleanup:
{ {
WOLFSSL_ENTER("wolfSSL_ERR_get_error"); WOLFSSL_ENTER("wolfSSL_ERR_get_error");
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
{ {
unsigned long ret = wolfSSL_ERR_peek_error_line_data(NULL, NULL, unsigned long ret = wolfSSL_ERR_peek_error_line_data(NULL, NULL,
@@ -17693,7 +17694,7 @@ cleanup:
wc_RemoveErrorNode(-1); wc_RemoveErrorNode(-1);
return ret; return ret;
} }
#elif (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) #else
{ {
int ret = wc_PullErrorNode(NULL, NULL, NULL); int ret = wc_PullErrorNode(NULL, NULL, NULL);
@@ -17709,12 +17710,13 @@ cleanup:
return (unsigned long)ret; return (unsigned long)ret;
} }
#endif
#else #else
return (unsigned long)(0 - NOT_COMPILED_IN); return (unsigned long)(0 - NOT_COMPILED_IN);
#endif #endif
} }
#if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) #ifdef WOLFSSL_HAVE_ERROR_QUEUE
#ifndef NO_BIO #ifndef NO_BIO
/* print out and clear all errors */ /* print out and clear all errors */
void wolfSSL_ERR_print_errors(WOLFSSL_BIO* bio) void wolfSSL_ERR_print_errors(WOLFSSL_BIO* bio)
@@ -17747,7 +17749,7 @@ cleanup:
} }
} }
#endif /* !NO_BIO */ #endif /* !NO_BIO */
#endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */ #endif /* WOLFSSL_HAVE_ERROR_QUEUE */
#endif /* OPENSSL_EXTRA || HAVE_WEBSERVER */ #endif /* OPENSSL_EXTRA || HAVE_WEBSERVER */
@@ -19475,9 +19477,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
void wolfSSL_ERR_clear_error(void) void wolfSSL_ERR_clear_error(void)
{ {
WOLFSSL_ENTER("wolfSSL_ERR_clear_error"); WOLFSSL_ENTER("wolfSSL_ERR_clear_error");
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX) || \
defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
wc_ClearErrorNodes(); wc_ClearErrorNodes();
#endif #endif
} }
@@ -19951,7 +19951,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
*/ */
unsigned long wolfSSL_ERR_get_error_line(const char** file, int* line) unsigned long wolfSSL_ERR_get_error_line(const char** file, int* line)
{ {
#ifdef DEBUG_WOLFSSL #ifdef WOLFSSL_HAVE_ERROR_QUEUE
int ret = wc_PullErrorNode(file, NULL, line); int ret = wc_PullErrorNode(file, NULL, line);
if (ret < 0) { if (ret < 0) {
if (ret == BAD_STATE_E) return 0; /* no errors in queue */ if (ret == BAD_STATE_E) return 0; /* no errors in queue */
@@ -20057,9 +20057,10 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
unsigned long wolfSSL_ERR_get_error_line_data(const char** file, int* line, unsigned long wolfSSL_ERR_get_error_line_data(const char** file, int* line,
const char** data, int *flags) const char** data, int *flags)
{ {
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
int ret; int ret;
WOLFSSL_STUB("wolfSSL_ERR_get_error_line_data"); WOLFSSL_ENTER("wolfSSL_ERR_get_error_line_data");
if (flags != NULL) { if (flags != NULL) {
if ((*flags & ERR_TXT_STRING) == ERR_TXT_STRING) { if ((*flags & ERR_TXT_STRING) == ERR_TXT_STRING) {
@@ -20090,6 +20091,15 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
} }
return (unsigned long)ret; return (unsigned long)ret;
#else
WOLFSSL_ENTER("wolfSSL_ERR_get_error_line_data");
WOLFSSL_MSG("Error queue turned off, can not get error line");
(void)file;
(void)line;
(void)data;
(void)flags;
return 0;
#endif
} }
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
@@ -44382,10 +44392,8 @@ err:
} }
if ((l = wolfSSL_BIO_get_len(bio)) <= 0) { if ((l = wolfSSL_BIO_get_len(bio)) <= 0) {
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX)
/* No certificate in buffer */ /* No certificate in buffer */
WOLFSSL_ERROR(ASN_NO_PEM_HEADER); WOLFSSL_ERROR(ASN_NO_PEM_HEADER);
#endif
return WOLFSSL_FAILURE; return WOLFSSL_FAILURE;
} }
@@ -44632,6 +44640,7 @@ err:
} }
} }
else { else {
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
int err = (int)wolfSSL_ERR_peek_last_error(); int err = (int)wolfSSL_ERR_peek_last_error();
if (ERR_GET_LIB(err) == ERR_LIB_PEM && if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
@@ -44644,6 +44653,13 @@ err:
*/ */
wc_RemoveErrorNode(-1); wc_RemoveErrorNode(-1);
} }
#else
if (wolfSSL_sk_X509_INFO_num(localSk) > 0) {
WOLFSSL_MSG("At least one X509_INFO object on stack."
"Assuming error means EOF or no more PEM"
"headers found.");
}
#endif
else { else {
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
@@ -45921,8 +45937,7 @@ unsigned long wolfSSL_ERR_peek_last_error_line(const char **file, int *line)
(void)line; (void)line;
(void)file; (void)file;
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(DEBUG_WOLFSSL) || \ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
defined(WOLFSSL_HAPROXY)
{ {
int ret; int ret;
@@ -48283,7 +48298,7 @@ unsigned long wolfSSL_ERR_peek_last_error(void)
{ {
WOLFSSL_ENTER("wolfSSL_ERR_peek_last_error"); WOLFSSL_ENTER("wolfSSL_ERR_peek_last_error");
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_NGINX) #ifdef WOLFSSL_HAVE_ERROR_QUEUE
{ {
int ret; int ret;
@@ -49361,9 +49376,7 @@ unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line,
*flags = 0; *flags = 0;
} }
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
defined(WOLFSSL_OPENSSH) || defined(WOLFSSL_HAPROXY) || \
defined(WOLFSSL_MYSQL_COMPATIBLE)
{ {
int ret = 0; int ret = 0;

View File

@@ -456,8 +456,7 @@ WOLFSSL_API int WOLFSSL_IS_DEBUG_ON(void)
defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
defined(OPENSSL_EXTRA) defined(OPENSSL_EXTRA)
#if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && !defined(NO_ERROR_QUEUE)) \ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
|| defined(DEBUG_WOLFSSL_VERBOSE)
void WOLFSSL_ERROR_LINE(int error, const char* func, unsigned int line, void WOLFSSL_ERROR_LINE(int error, const char* func, unsigned int line,
const char* file, void* usrCtx) const char* file, void* usrCtx)
#else #else
@@ -470,8 +469,7 @@ void WOLFSSL_ERROR(int error)
{ {
char buffer[WOLFSSL_MAX_ERROR_SZ]; char buffer[WOLFSSL_MAX_ERROR_SZ];
#if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && \ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
!defined(NO_ERROR_QUEUE)) || defined(DEBUG_WOLFSSL_VERBOSE)
(void)usrCtx; /* a user ctx for future flexibility */ (void)usrCtx; /* a user ctx for future flexibility */
(void)func; (void)func;
@@ -577,6 +575,7 @@ int wc_LoggingCleanup(void)
int wc_PeekErrorNode(int idx, const char **file, const char **reason, int wc_PeekErrorNode(int idx, const char **file, const char **reason,
int *line) int *line)
{ {
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
struct wc_error_queue* err; struct wc_error_queue* err;
if (wc_LockMutex(&debug_mutex) != 0) { if (wc_LockMutex(&debug_mutex) != 0) {
@@ -622,6 +621,14 @@ int wc_PeekErrorNode(int idx, const char **file, const char **reason,
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
return err->value; return err->value;
#else
(void)idx;
(void)file;
(void)reason;
(void)line;
WOLFSSL_MSG("Error queue turned off, can not peak nodes");
return NOT_COMPILED_IN;
#endif
} }
@@ -637,6 +644,7 @@ int wc_PeekErrorNode(int idx, const char **file, const char **reason,
*/ */
int wc_PullErrorNode(const char **file, const char **reason, int *line) int wc_PullErrorNode(const char **file, const char **reason, int *line)
{ {
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
struct wc_error_queue* err; struct wc_error_queue* err;
int value; int value;
@@ -669,6 +677,13 @@ int wc_PullErrorNode(const char **file, const char **reason, int *line)
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
return value; return value;
#else
(void)file;
(void)reason;
(void)line;
WOLFSSL_MSG("Error queue turned off, can not pull nodes");
return NOT_COMPILED_IN;
#endif
} }
@@ -677,13 +692,7 @@ int wc_PullErrorNode(const char **file, const char **reason, int *line)
* function. debug_mutex should be locked before a call to this function. */ * function. debug_mutex should be locked before a call to this function. */
int wc_AddErrorNode(int error, int line, char* buf, char* file) int wc_AddErrorNode(int error, int line, char* buf, char* file)
{ {
#if defined(NO_ERROR_QUEUE) #ifdef WOLFSSL_HAVE_ERROR_QUEUE
(void)error;
(void)line;
(void)buf;
(void)file;
WOLFSSL_MSG("Error queue turned off, can not add nodes");
#else
struct wc_error_queue* err; struct wc_error_queue* err;
if (wc_error_queue_count >= ERROR_QUEUE_MAX) { if (wc_error_queue_count >= ERROR_QUEUE_MAX) {
@@ -757,8 +766,15 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
} }
wc_error_queue_count++; wc_error_queue_count++;
} }
#endif
return 0; return 0;
#else
(void)error;
(void)line;
(void)buf;
(void)file;
WOLFSSL_MSG("Error queue turned off, can not add nodes");
return NOT_COMPILED_IN;
#endif
} }
/* Removes the error node at the specified index. /* Removes the error node at the specified index.
@@ -767,6 +783,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
*/ */
void wc_RemoveErrorNode(int idx) void wc_RemoveErrorNode(int idx)
{ {
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
struct wc_error_queue* current; struct wc_error_queue* current;
if (wc_LockMutex(&debug_mutex) != 0) { if (wc_LockMutex(&debug_mutex) != 0) {
@@ -797,6 +814,10 @@ void wc_RemoveErrorNode(int idx)
} }
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
#else
(void)idx;
WOLFSSL_MSG("Error queue turned off, can not remove nodes");
#endif
} }
@@ -804,9 +825,7 @@ void wc_RemoveErrorNode(int idx)
*/ */
void wc_ClearErrorNodes(void) void wc_ClearErrorNodes(void)
{ {
#if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_NGINX) || \ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
if (wc_LockMutex(&debug_mutex) != 0) { if (wc_LockMutex(&debug_mutex) != 0) {
WOLFSSL_MSG("Lock debug mutex failed"); WOLFSSL_MSG("Lock debug mutex failed");
return; return;
@@ -830,7 +849,9 @@ void wc_ClearErrorNodes(void)
wc_last_node = NULL; wc_last_node = NULL;
wc_current_node = NULL; wc_current_node = NULL;
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
#endif /* DEBUG_WOLFSSL || WOLFSSL_NGINX */ #else
WOLFSSL_MSG("Error queue turned off, can not clear nodes");
#endif
} }
int wc_SetLoggingHeap(void* h) int wc_SetLoggingHeap(void* h)

View File

@@ -105,6 +105,12 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
WOLFSSL_API const char *wolfSSL_global_cflags(void); WOLFSSL_API const char *wolfSSL_global_cflags(void);
#endif #endif
#if (defined(OPENSSL_EXTRA) && !defined(_WIN32) && \
!defined(NO_ERROR_QUEUE)) || defined(DEBUG_WOLFSSL_VERBOSE)
#define WOLFSSL_HAVE_ERROR_QUEUE
#endif
#if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE) #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
WOLFSSL_LOCAL int wc_LoggingInit(void); WOLFSSL_LOCAL int wc_LoggingInit(void);
WOLFSSL_LOCAL int wc_LoggingCleanup(void); WOLFSSL_LOCAL int wc_LoggingCleanup(void);
@@ -175,8 +181,7 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
#if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\ #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
#if (!defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && !defined(_WIN32))\ #ifdef WOLFSSL_HAVE_ERROR_QUEUE
|| defined(DEBUG_WOLFSSL_VERBOSE)
WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line, WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
const char* file, void* ctx); const char* file, void* ctx);
#define WOLFSSL_ERROR(x) \ #define WOLFSSL_ERROR(x) \