Merge pull request #4448 from JacobBarthelmeh/Compatibility-Layer

remove error queue from JNI build and set a default upper bound on it
pull/4458/head
Sean Parkinson 2021-10-08 08:35:03 +10:00 committed by GitHub
commit dd6e4093b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 8 deletions

View File

@ -2436,12 +2436,6 @@ AC_ARG_ENABLE([errorqueue],
[ ENABLED_ERROR_QUEUE=yes ] [ ENABLED_ERROR_QUEUE=yes ]
) )
if test "$ENABLED_ERROR_QUEUE" = "no"
then
AM_CFLAGS="$AM_CFLAGS -DNO_ERROR_QUEUE"
fi
# OLD TLS # OLD TLS
AC_ARG_ENABLE([oldtls], AC_ARG_ENABLE([oldtls],
[AS_HELP_STRING([--enable-oldtls],[Enable old TLS versions < 1.2 (default: enabled)])], [AS_HELP_STRING([--enable-oldtls],[Enable old TLS versions < 1.2 (default: enabled)])],
@ -6462,13 +6456,17 @@ 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"])
if test "$ENABLED_ED25519_STREAM" != "no" if test "$ENABLED_ED25519_STREAM" != "no"
then then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ED25519_STREAMING_VERIFY" AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ED25519_STREAMING_VERIFY"
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_ED25519_STREAMING_VERIFY" AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_ED25519_STREAMING_VERIFY"
fi fi
if test "$ENABLED_ERROR_QUEUE" = "no" || test "$ENABLED_JNI" = "yes"
then
AM_CFLAGS="$AM_CFLAGS -DNO_ERROR_QUEUE"
fi
AS_IF([test "x$ENABLED_OPENSSLALL" = "xyes"], AS_IF([test "x$ENABLED_OPENSSLALL" = "xyes"],
[AM_CFLAGS="-DOPENSSL_ALL -DWOLFSSL_EITHER_SIDE -DWC_RSA_NO_PADDING -DWC_RSA_PSS -DWOLFSSL_PSS_LONG_SALT $AM_CFLAGS"]) [AM_CFLAGS="-DOPENSSL_ALL -DWOLFSSL_EITHER_SIDE -DWC_RSA_NO_PADDING -DWC_RSA_PSS -DWOLFSSL_PSS_LONG_SALT $AM_CFLAGS"])

View File

@ -36130,6 +36130,19 @@ static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
} }
AssertIntEQ(errorCount, ERROR_COUNT); AssertIntEQ(errorCount, ERROR_COUNT);
/* test max queue behavior, trying to add an arbitrary 3 errors over */
errorCount = 0;
for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
while ((err = ERR_get_error_line(&file, &line))) {
AssertIntEQ(err, 990 + errorCount);
errorCount++;
}
/* test that the 3 errors over the max were dropped */
AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
return 0; return 0;
} }
#endif #endif

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,6 +485,7 @@ 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) { if (wc_AddErrorNode(error, line, buffer, (char*)file) != 0) {
WOLFSSL_MSG("Error creating logging node"); WOLFSSL_MSG("Error creating logging node");
/* with void function there is no return here, continue on /* with void function there is no return here, continue on
@ -484,7 +496,6 @@ void WOLFSSL_ERROR(int error)
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 +533,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;
@ -667,6 +679,12 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
WOLFSSL_MSG("Error queue turned off, can not add nodes"); WOLFSSL_MSG("Error queue turned off, can not add nodes");
#else #else
struct wc_error_queue* err; struct wc_error_queue* err;
if (wc_error_queue_count >= ERROR_QUEUE_MAX) {
WOLFSSL_MSG("Error queue is full, at ERROR_QUEUE_MAX");
return MEMORY_E;
}
err = (struct wc_error_queue*)XMALLOC( err = (struct wc_error_queue*)XMALLOC(
sizeof(struct wc_error_queue), wc_error_heap, DYNAMIC_TYPE_LOG); sizeof(struct wc_error_queue), wc_error_heap, DYNAMIC_TYPE_LOG);
if (err == NULL) { if (err == NULL) {
@ -731,6 +749,7 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
wc_current_node = err; wc_current_node = err;
} }
} }
wc_error_queue_count++;
} }
#endif #endif
return 0; return 0;
@ -768,6 +787,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 +819,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 +861,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 +911,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;