mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 03:34:39 +02:00
resolve rebase by adding an error node pull function
This commit is contained in:
15
src/ssl.c
15
src/ssl.c
@@ -14327,15 +14327,12 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
unsigned long wolfSSL_ERR_get_error_line(const char** file, int* line)
|
||||
{
|
||||
#ifdef DEBUG_WOLFSSL
|
||||
if (file != NULL) {
|
||||
*file = (const char*)wc_last_error_file;
|
||||
int ret = wc_PullErrorNode(file, NULL, line);
|
||||
if (ret < 0) {
|
||||
WOLFSSL_MSG("Issue getting error node");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (line != NULL) {
|
||||
*line = (int)wc_last_error_line;
|
||||
}
|
||||
|
||||
return wc_last_error;
|
||||
return (unsigned long)ret;
|
||||
#else
|
||||
(void)file;
|
||||
(void)line;
|
||||
@@ -24227,7 +24224,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_bio_PrivateKey(WOLFSSL_BIO* bio,
|
||||
}
|
||||
|
||||
if (cb == NULL) {
|
||||
localCb = &OurPasswordCb;
|
||||
localCb = OurPasswordCb;
|
||||
}
|
||||
wolfSSL_CTX_set_default_passwd_cb(info->ctx, localCb);
|
||||
wolfSSL_CTX_set_default_passwd_cb_userdata(info->ctx, pass);
|
||||
|
@@ -14896,6 +14896,11 @@ static void test_wolfSSL_ERR_put_error(void)
|
||||
ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
|
||||
AssertIntEQ(ERR_get_error_line(&file, &line), 15);
|
||||
|
||||
/* try reading past end of error queue */
|
||||
file = NULL;
|
||||
AssertIntEQ(ERR_get_error_line(&file, &line), 0);
|
||||
AssertNull(file);
|
||||
|
||||
printf(resultFmt, passed);
|
||||
#endif
|
||||
}
|
||||
|
@@ -48,6 +48,7 @@ struct wc_error_queue {
|
||||
int line;
|
||||
};
|
||||
volatile struct wc_error_queue* wc_errors;
|
||||
static struct wc_error_queue* wc_current_node;
|
||||
static struct wc_error_queue* wc_last_node;
|
||||
/* pointer to last node in queue to make insertion O(1) */
|
||||
#endif
|
||||
@@ -292,6 +293,7 @@ int wc_LoggingInit(void)
|
||||
return BAD_MUTEX_E;
|
||||
}
|
||||
wc_errors = NULL;
|
||||
wc_current_node = NULL;
|
||||
wc_last_node = NULL;
|
||||
|
||||
return 0;
|
||||
@@ -376,6 +378,51 @@ int wc_PeekErrorNode(int idx, const char **file, const char **reason,
|
||||
}
|
||||
|
||||
|
||||
/* Pulls the current node from error queue and increments current state.
|
||||
* Note: this does not delete nodes because input arguments are pointing to
|
||||
* node buffers.
|
||||
*
|
||||
* file pointer to file that error was in. Can be NULL to return no file.
|
||||
* reason error string giving reason for error. Can be NULL to return no reason.
|
||||
* line retrun line number of where error happened.
|
||||
*/
|
||||
int wc_PullErrorNode(const char **file, const char **reason, int *line)
|
||||
{
|
||||
struct wc_error_queue* err;
|
||||
int value;
|
||||
|
||||
if (wc_LockMutex(&debug_mutex) != 0) {
|
||||
WOLFSSL_MSG("Lock debug mutex failed");
|
||||
return BAD_MUTEX_E;
|
||||
}
|
||||
|
||||
err = wc_current_node;
|
||||
if (err == NULL) {
|
||||
WOLFSSL_MSG("No Errors in queue");
|
||||
wc_UnLockMutex(&debug_mutex);
|
||||
return BAD_STATE_E;
|
||||
}
|
||||
|
||||
if (file != NULL) {
|
||||
*file = err->file;
|
||||
}
|
||||
|
||||
if (reason != NULL) {
|
||||
*reason = err->error;
|
||||
}
|
||||
|
||||
if (line != NULL) {
|
||||
*line = err->line;
|
||||
}
|
||||
|
||||
value = err->value;
|
||||
wc_current_node = err->next;
|
||||
wc_UnLockMutex(&debug_mutex);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* create new error node and add it to the queue
|
||||
* buffers are assumed to be of size WOLFSSL_MAX_ERROR_SZ for this internal
|
||||
* function. debug_mutex should be locked before a call to this function. */
|
||||
@@ -429,12 +476,19 @@ int wc_AddErrorNode(int error, int line, char* buf, char* file)
|
||||
else {
|
||||
wc_errors = err;
|
||||
wc_last_node = err;
|
||||
wc_current_node = err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wc_last_node->next = err;
|
||||
err->prev = wc_last_node;
|
||||
wc_last_node = err;
|
||||
|
||||
/* check the case where have read to the end of the queue and the
|
||||
* current node to read needs updated */
|
||||
if (wc_current_node == NULL) {
|
||||
wc_current_node = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -61,6 +61,8 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void);
|
||||
const char **reason, int *line);
|
||||
WOLFSSL_LOCAL void wc_RemoveErrorNode(int index);
|
||||
WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
|
||||
WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
|
||||
int *line);
|
||||
WOLFSSL_API int wc_SetLoggingHeap(void* h);
|
||||
#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
|
||||
WOLFSSL_API void wc_ERR_print_errors_fp(FILE* fp);
|
||||
|
Reference in New Issue
Block a user