remove error queue from JNI build and put a default max on error queue size

This commit is contained in:
Jacob Barthelmeh
2021-10-04 11:45:18 -06:00
parent 0bee624ee5
commit 40ac1c4dd2
2 changed files with 32 additions and 5 deletions

View File

@ -6447,6 +6447,9 @@ AS_IF([test "x$ENABLED_ED25519" = "xyes" && test "x$ENABLED_32BIT" = "xno"],
AS_IF([test "x$ENABLED_ED25519_SMALL" = "xyes"], AS_IF([test "x$ENABLED_ED25519_SMALL" = "xyes"],
[AM_CFLAGS="$AM_CFLAGS -DED25519_SMALL"]) [AM_CFLAGS="$AM_CFLAGS -DED25519_SMALL"])
# Turn off error queue with JNI Java use
AS_IF([test "x$ENABLED_JNI" = "xyes"],
[AM_CFLAGS="$AM_CFLAGS -DNO_ERROR_QUEUE"])
if test "$ENABLED_ED25519_STREAM" != "no" if test "$ENABLED_ED25519_STREAM" != "no"
then then

View File

@ -71,6 +71,17 @@ THREAD_LS_T
#endif #endif
struct wc_error_queue* wc_last_node; struct wc_error_queue* wc_last_node;
/* pointer to last node in queue to make insertion O(1) */ /* pointer to last node in queue to make insertion O(1) */
#ifndef ERROR_QUEUE_MAX
/* this breaks from compat of unlimited error queue size */
#define ERROR_QUEUE_MAX 100
#endif
static
#ifdef ERROR_QUEUE_PER_THREAD
THREAD_LS_T
#endif
int wc_error_queue_count = 0;
#endif #endif
#ifdef WOLFSSL_FUNC_TIME #ifdef WOLFSSL_FUNC_TIME
@ -474,17 +485,25 @@ void WOLFSSL_ERROR(int error)
XSNPRINTF(buffer, sizeof(buffer), XSNPRINTF(buffer, sizeof(buffer),
"wolfSSL error occurred, error = %d line:%d file:%s", "wolfSSL error occurred, error = %d line:%d file:%s",
error, line, file); error, line, file);
if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) {
WOLFSSL_MSG("Error creating logging node"); if (wc_error_queue_count >= ERROR_QUEUE_MAX) {
/* with void function there is no return here, continue on WOLFSSL_MSG("Error queue is full, at ERROR_QUEUE_MAX");
* to unlock mutex and log what buffer was created. */ }
else {
if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) {
WOLFSSL_MSG("Error creating logging node");
/* with void function there is no return here, continue on
* to unlock mutex and log what buffer was created. */
}
else {
wc_error_queue_count++;
}
} }
#if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
} }
else { else {
XSNPRINTF(buffer, sizeof(buffer), XSNPRINTF(buffer, sizeof(buffer),
"wolfSSL error occurred, error = %d", error); "wolfSSL error occurred, error = %d", error);
} }
#endif #endif
@ -522,6 +541,7 @@ int wc_LoggingInit(void)
WOLFSSL_MSG("Bad Init Mutex"); WOLFSSL_MSG("Bad Init Mutex");
return BAD_MUTEX_E; return BAD_MUTEX_E;
} }
wc_error_queue_count = 0;
wc_errors = NULL; wc_errors = NULL;
wc_current_node = NULL; wc_current_node = NULL;
wc_last_node = NULL; wc_last_node = NULL;
@ -768,6 +788,7 @@ void wc_RemoveErrorNode(int idx)
if (wc_current_node == current) if (wc_current_node == current)
wc_current_node = current->next; wc_current_node = current->next;
XFREE(current, current->heap, DYNAMIC_TYPE_LOG); XFREE(current, current->heap, DYNAMIC_TYPE_LOG);
wc_error_queue_count--;
} }
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
@ -799,6 +820,7 @@ void wc_ClearErrorNodes(void)
} }
} }
wc_error_queue_count = 0;
wc_errors = NULL; wc_errors = NULL;
wc_last_node = NULL; wc_last_node = NULL;
wc_current_node = NULL; wc_current_node = NULL;
@ -840,6 +862,7 @@ int wc_ERR_remove_state(void)
current = next; current = next;
} }
wc_error_queue_count = 0;
wc_errors = NULL; wc_errors = NULL;
wc_last_node = NULL; wc_last_node = NULL;
@ -889,6 +912,7 @@ void wc_ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
} }
/* set global pointers to match having been freed */ /* set global pointers to match having been freed */
wc_error_queue_count = 0;
wc_errors = NULL; wc_errors = NULL;
wc_last_node = NULL; wc_last_node = NULL;