@@ -17045,51 +17045,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1704517045
1704617046 unsigned long wolfSSL_ERR_get_error(void)
1704717047 {
17048- int ret;
17049-
1705017048 WOLFSSL_ENTER("wolfSSL_ERR_get_error");
17051-
1705217049#ifdef WOLFSSL_HAVE_ERROR_QUEUE
17053- ret = wc_PullErrorNode(NULL, NULL, NULL);
17054- if (ret < 0) {
17055- if (ret == BAD_STATE_E) {
17056- ret = 0; /* no errors in queue */
17057- }
17058- else {
17059- WOLFSSL_MSG("Error with pulling error node!");
17060- WOLFSSL_LEAVE("wolfSSL_ERR_get_error", ret);
17061- ret = 0 - ret; /* return absolute value of error */
17062- /* panic and try to clear out nodes */
17063- wc_ClearErrorNodes();
17064- }
17065- }
17066- else {
17067- int idx = wc_GetCurrentIdx();
17068- if (idx < 0) {
17069- WOLFSSL_MSG("Error with getting current index!");
17070- ret = BAD_STATE_E;
17071- WOLFSSL_LEAVE("wolfSSL_ERR_get_error", ret);
17072-
17073- /* panic and try to clear out nodes and reset queue state */
17074- wc_ClearErrorNodes();
17075- }
17076- else if (idx > 0) {
17077- idx -= 1;
17078- wc_RemoveErrorNode(idx);
17079- }
17080- else {
17081- /* if current idx is 0 then the queue only had one node */
17082- wc_RemoveErrorNode(idx);
17083- }
17084- }
17085-
17086- return ret;
17050+ return wc_GetErrorNodeErr();
1708717051#else
17088-
17089- (void)ret;
17090-
1709117052 return (unsigned long)(0 - NOT_COMPILED_IN);
17092- #endif /* WOLFSSL_HAVE_ERROR_QUEUE */
17053+ #endif
1709317054 }
1709417055
1709517056#ifdef WOLFSSL_HAVE_ERROR_QUEUE
@@ -33220,63 +33181,42 @@ int wolfSSL_AsyncPoll(WOLFSSL* ssl, WOLF_EVENT_FLAG flags)
3322033181#endif /* WOLFSSL_ASYNC_CRYPT */
3322133182
3322233183#ifdef OPENSSL_EXTRA
33184+
33185+ static int peek_ignore_err(int err)
33186+ {
33187+ switch(err) {
33188+ case -WANT_READ:
33189+ case -WANT_WRITE:
33190+ case -ZERO_RETURN:
33191+ case -WOLFSSL_ERROR_ZERO_RETURN:
33192+ case -SOCKET_PEER_CLOSED_E:
33193+ case -SOCKET_ERROR_E:
33194+ return 1;
33195+ default:
33196+ return 0;
33197+ }
33198+ }
33199+
3322333200unsigned long wolfSSL_ERR_peek_error_line_data(const char **file, int *line,
3322433201 const char **data, int *flags)
3322533202{
33226- WOLFSSL_ENTER("wolfSSL_ERR_peek_error_line_data");
33227-
33228- (void)line;
33229- (void)file;
33230-
33231- /* No data or flags stored - error display only in Nginx. */
33232- if (data != NULL) {
33233- *data = "";
33234- }
33235- if (flags != NULL) {
33236- *flags = 0;
33237- }
33238-
33239- #ifdef WOLFSSL_HAVE_ERROR_QUEUE
33240- {
33241- int ret = 0;
33242- int idx = wc_GetCurrentIdx();
33243-
33244- while (1) {
33245- ret = wc_PeekErrorNode(idx, file, NULL, line);
33246- if (ret == BAD_MUTEX_E || ret == BAD_FUNC_ARG || ret == BAD_STATE_E) {
33247- WOLFSSL_MSG("Issue peeking at error node in queue");
33248- return 0;
33249- }
33250- /* OpenSSL uses positive error codes */
33251- if (ret < 0) {
33252- ret = -ret;
33253- }
33203+ unsigned long err;
3325433204
33255- if (ret == -ASN_NO_PEM_HEADER)
33256- return (ERR_LIB_PEM << 24) | PEM_R_NO_START_LINE;
33257- #ifdef OPENSSL_ALL
33258- /* PARSE_ERROR is returned if an HTTP request is detected. */
33259- if (ret == -SSL_R_HTTP_REQUEST)
33260- return (ERR_LIB_SSL << 24) | -SSL_R_HTTP_REQUEST;
33261- #endif
33262- #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
33263- if (ret == ASN1_R_HEADER_TOO_LONG) {
33264- return (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG;
33265- }
33266- #endif
33267- if (ret != -WANT_READ && ret != -WANT_WRITE &&
33268- ret != -ZERO_RETURN && ret != -WOLFSSL_ERROR_ZERO_RETURN &&
33269- ret != -SOCKET_PEER_CLOSED_E && ret != -SOCKET_ERROR_E)
33270- break;
33271-
33272- wc_RemoveErrorNode(idx);
33273- }
33205+ WOLFSSL_ENTER("wolfSSL_ERR_peek_error_line_data");
33206+ err = wc_PeekErrorNodeLineData(file, line, data, flags, peek_ignore_err);
3327433207
33275- return (unsigned long)ret;
33276- }
33277- #else
33278- return (unsigned long)(0 - NOT_COMPILED_IN);
33208+ if (err == -ASN_NO_PEM_HEADER)
33209+ return (ERR_LIB_PEM << 24) | PEM_R_NO_START_LINE;
33210+ #ifdef OPENSSL_ALL
33211+ /* PARSE_ERROR is returned if an HTTP request is detected. */
33212+ else if (err == -SSL_R_HTTP_REQUEST)
33213+ return (ERR_LIB_SSL << 24) | -SSL_R_HTTP_REQUEST;
33214+ #endif
33215+ #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
33216+ else if (err == ASN1_R_HEADER_TOO_LONG)
33217+ return (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG;
3327933218#endif
33219+ return err;
3328033220}
3328133221#endif
3328233222
0 commit comments