account for 'pulled' error nodes

This commit is contained in:
JacobBarthelmeh
2022-11-17 14:51:37 -08:00
parent bd7b442df3
commit 143dac64a3
4 changed files with 49 additions and 10 deletions

View File

@@ -17075,7 +17075,11 @@ cleanup:
} }
} }
else { else {
wc_RemoveErrorNode(0); int idx = wc_GetCurrentIdx();
if (idx > 0) {
idx = idx -1;
}
wc_RemoveErrorNode(idx);
} }
return ret; return ret;
@@ -33241,9 +33245,10 @@ unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line,
#ifdef WOLFSSL_HAVE_ERROR_QUEUE #ifdef WOLFSSL_HAVE_ERROR_QUEUE
{ {
int ret = 0; int ret = 0;
int idx = wc_GetCurrentIdx();
while (1) { while (1) {
ret = wc_PeekErrorNode(0, file, NULL, line); ret = wc_PeekErrorNode(idx, file, NULL, line);
if (ret == BAD_MUTEX_E || ret == BAD_FUNC_ARG || ret == BAD_STATE_E) { if (ret == BAD_MUTEX_E || ret == BAD_FUNC_ARG || ret == BAD_STATE_E) {
WOLFSSL_MSG("Issue peeking at error node in queue"); WOLFSSL_MSG("Issue peeking at error node in queue");
return 0; return 0;
@@ -33270,7 +33275,7 @@ unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line,
ret != -SOCKET_PEER_CLOSED_E && ret != -SOCKET_ERROR_E) ret != -SOCKET_PEER_CLOSED_E && ret != -SOCKET_ERROR_E)
break; break;
wc_RemoveErrorNode(0); wc_RemoveErrorNode(idx);
} }
return (unsigned long)ret; return (unsigned long)ret;

View File

@@ -39821,7 +39821,7 @@ static int test_wolfSSL_ERR_put_error(void)
ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15); ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
AssertIntEQ(ERR_get_error_line(&file, &line), 15); AssertIntEQ(ERR_get_error_line(&file, &line), 15);
#ifdef WOLFSSL_PYTHON #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG, ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
"this file", 100); "this file", 100);
AssertIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line), AssertIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),

View File

@@ -597,8 +597,9 @@ int wc_LoggingCleanup(void)
/* peek at an error node /* peek at an error node
* *
* idx : if -1 then the most recent node is looked at, otherwise search * idx : if -1 then the most recent node is looked at,
* through queue for node at the given index * otherwise search through queue for node at the given index starting
* from the absolute head wc_errors
* file : pointer to internal file string * file : pointer to internal file string
* reason : pointer to internal error reason * reason : pointer to internal error reason
* line : line number that error happened at * line : line number that error happened at
@@ -811,9 +812,32 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
#endif #endif
} }
/* returns the current index into the queue, can be greater than zero in cases
* where wc_PullErrorNode() has been callded. */
int wc_GetCurrentIdx()
{
int ret = 0;
#ifdef WOLFSSL_HAVE_ERROR_QUEUE
struct wc_error_queue* current;
current = (struct wc_error_queue*)wc_errors;
while (current != wc_current_node && current != NULL) {
current = current->next;
ret++;
}
/* wc_current_node was not found in the list! use index 0 */
if (current == NULL) {
ret = 0;
}
#endif
return ret;
}
/* Removes the error node at the specified index. /* Removes the error node at the specified index.
* idx : if -1 then the most recent node is looked at, otherwise search * idx : if -1 then the most recent node is looked at,
* through queue for node at the given index * otherwise search through queue for node at the given index starting
* from the absolute head wc_errors
*/ */
void wc_RemoveErrorNode(int idx) void wc_RemoveErrorNode(int idx)
{ {
@@ -825,8 +849,9 @@ void wc_RemoveErrorNode(int idx)
return; return;
} }
if (idx == -1) if (idx == -1) {
current = wc_last_node; current = wc_last_node;
}
else { else {
current = (struct wc_error_queue*)wc_errors; current = (struct wc_error_queue*)wc_errors;
for (; current != NULL && idx > 0; idx--) for (; current != NULL && idx > 0; idx--)
@@ -845,6 +870,13 @@ void wc_RemoveErrorNode(int idx)
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_error_queue_count--;
/* last node left in list was free'd, reset list head */
if (wc_error_queue_count == 0) {
wc_errors = NULL;
wc_last_node = NULL;
wc_current_node = NULL;
}
} }
wc_UnLockMutex(&debug_mutex); wc_UnLockMutex(&debug_mutex);
@@ -865,7 +897,8 @@ void wc_ClearErrorNodes(void)
return; return;
} }
/* free all nodes from error queue */ /* free all nodes from error queue (even previously 'pulled' ones) starting
* at the lists absolute head of wc_errors */
{ {
struct wc_error_queue* current; struct wc_error_queue* current;
struct wc_error_queue* next; struct wc_error_queue* next;

View File

@@ -122,6 +122,7 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
WOLFSSL_LOCAL void wc_ClearErrorNodes(void); WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason, WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
int *line); int *line);
WOLFSSL_LOCAL int wc_GetCurrentIdx(void);
WOLFSSL_API int wc_SetLoggingHeap(void* h); WOLFSSL_API int wc_SetLoggingHeap(void* h);
WOLFSSL_API int wc_ERR_remove_state(void); WOLFSSL_API int wc_ERR_remove_state(void);
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)