Skip to content

Commit f086e91

Browse files
authored
Merge pull request #10234 from douzzer/20260415-trace-errcodes-fixes-and-tests
20260415-trace-errcodes-fixes-and-tests
2 parents 3c2a92d + 4cd7126 commit f086e91

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

.github/workflows/trackmemory.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
matrix:
1919
config: [
2020
# Add new configs here
21-
'--enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY"',
21+
'--enable-all --enable-debug-trace-errcodes CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY"',
2222
'--enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY"',
23-
'--enable-smallstackcache --enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY"',
23+
'--enable-smallstackcache --enable-smallstack --enable-all --enable-debug-trace-errcodes CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY"',
2424
# Note the below smallstackcache tests are crucial coverage for the Linux kernel
2525
# module, when targeting a kernel with the randomness patch (linuxkm/patches/)
2626
# applied.

tests/api/test_aes.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8754,7 +8754,8 @@ int test_wc_AesCtr_MonteCarlo(void)
87548754
int test_wc_AesGcm_MonteCarlo(void)
87558755
{
87568756
EXPECT_DECLS;
8757-
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(HAVE_AES_DECRYPT)
8757+
#if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(HAVE_AES_DECRYPT) && \
8758+
!defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO)
87588759
static const word32 keySizes[] = {
87598760
#ifdef WOLFSSL_AES_128
87608761
16,
@@ -8815,7 +8816,9 @@ int test_wc_AesGcm_MonteCarlo(void)
88158816
WC_FREE_VAR(plain, NULL);
88168817
WC_FREE_VAR(cipher, NULL);
88178818
WC_FREE_VAR(decrypted, NULL);
8818-
#endif
8819+
#endif /* !NO_AES && HAVE_AESGCM && HAVE_AES_DECRYPT && !WOLFSSL_AFALG && */
8820+
/* !WOLFSSL_DEVCRYPTO */
8821+
88198822
return EXPECT_RESULT();
88208823
}
88218824

wolfcrypt/src/logging.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,33 @@ int wc_backtrace_render(void) {
18701870

18711871
#include <backtrace.h>
18721872

1873+
#ifdef XFILE
1874+
1875+
static XFILE wolfssl_backtrace_file = XBADFILE;
1876+
1877+
XFILE wc_backtrace_set_fp(XFILE new_fp) {
1878+
XFILE old_fp = wolfssl_backtrace_file;
1879+
if (new_fp == NULL)
1880+
wolfssl_backtrace_file = XBADFILE;
1881+
else
1882+
wolfssl_backtrace_file = new_fp;
1883+
return old_fp;
1884+
}
1885+
1886+
#define WOLFSSL_BACKTRACE_PRINTF(...) ( \
1887+
(wolfssl_backtrace_file == XBADFILE) ? \
1888+
WOLFSSL_DEBUG_PRINTF(__VA_ARGS__) : \
1889+
WOLFSSL_DEBUG_PRINTF_FN(wolfssl_backtrace_file, __VA_ARGS__))
1890+
1891+
#else /* !XFILE */
1892+
1893+
/* libbacktrace doesn't support any targets with no XFILE, but keep it buildable
1894+
* just in case.
1895+
*/
1896+
#define WOLFSSL_BACKTRACE_PRINTF(...) WOLFSSL_DEBUG_PRINTF(__VA_ARGS__)
1897+
1898+
#endif /* !XFILE */
1899+
18731900
static int backtrace_callback(void *data, uintptr_t pc, const char *filename,
18741901
int lineno, const char *function)
18751902
{
@@ -1880,20 +1907,20 @@ static int backtrace_callback(void *data, uintptr_t pc, const char *filename,
18801907
*(int *)data = 1;
18811908
return 0;
18821909
}
1883-
WOLFSSL_DEBUG_PRINTF(" #%d %p in %s %s:%d\n", (*(int *)data)++,
1910+
WOLFSSL_BACKTRACE_PRINTF(" #%d %p in %s %s:%d\n", (*(int *)data)++,
18841911
(void *)pc, function, filename, lineno);
18851912
return 0;
18861913
}
18871914

18881915
static void backtrace_error(void *data, const char *msg, int errnum) {
18891916
(void)data;
1890-
WOLFSSL_DEBUG_PRINTF("ERR TRACE: error %d while backtracing: %s",
1917+
WOLFSSL_BACKTRACE_PRINTF("ERR TRACE: error %d while backtracing: %s",
18911918
errnum, msg);
18921919
}
18931920

18941921
static void backtrace_creation_error(void *data, const char *msg, int errnum) {
18951922
(void)data;
1896-
WOLFSSL_DEBUG_PRINTF("ERR TRACE: internal error %d "
1923+
WOLFSSL_BACKTRACE_PRINTF("ERR TRACE: internal error %d "
18971924
"while initializing backtrace facility: %s", errnum, msg);
18981925
}
18991926

wolfcrypt/test/test.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41506,31 +41506,31 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
4150641506
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
4150741507

4150841508
#ifdef WOLFSSL_SE050
41509-
#define RARE_ED_BAD_ENC_E WC_HW_E
41510-
#define RARE_ED_BAD_SIG_E WC_HW_E
41509+
#define RARE_ED_BAD_ENC_E WC_NO_ERR_TRACE(WC_HW_E)
41510+
#define RARE_ED_BAD_SIG_E WC_NO_ERR_TRACE(WC_HW_E)
4151141511
#else
41512-
#define RARE_ED_BAD_ENC_E BAD_FUNC_ARG
41513-
#define RARE_ED_BAD_SIG_E SIG_VERIFY_E
41512+
#define RARE_ED_BAD_ENC_E WC_NO_ERR_TRACE(BAD_FUNC_ARG)
41513+
#define RARE_ED_BAD_SIG_E WC_NO_ERR_TRACE(SIG_VERIFY_E)
4151441514
#endif
4151541515

4151641516
ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
4151741517
&verify, key);
41518-
if (ret != WC_NO_ERR_TRACE(RARE_ED_BAD_ENC_E))
41518+
if (ret != RARE_ED_BAD_ENC_E)
4151941519
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
4152041520

4152141521
ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
4152241522
&verify, key);
41523-
if (ret != WC_NO_ERR_TRACE(RARE_ED_BAD_ENC_E))
41523+
if (ret != RARE_ED_BAD_ENC_E)
4152441524
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
4152541525

4152641526
ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
4152741527
&verify, key);
41528-
if (ret != WC_NO_ERR_TRACE(RARE_ED_BAD_ENC_E))
41528+
if (ret != RARE_ED_BAD_ENC_E)
4152941529
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
4153041530

4153141531
ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
4153241532
&verify, key);
41533-
if (ret != WC_NO_ERR_TRACE(RARE_ED_BAD_SIG_E))
41533+
if (ret != RARE_ED_BAD_SIG_E)
4153441534
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
4153541535

4153641536
#undef RARE_ED_BAD_ENC_E

wolfssl/wolfcrypt/logging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix);
582582
#ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES
583583
WOLFSSL_API int wc_debug_trace_error_codes_enabled(void);
584584
WOLFSSL_API int wc_debug_trace_error_codes_set(int state);
585+
#ifdef XFILE
586+
WOLFSSL_API XFILE wc_backtrace_set_fp(XFILE new_fp);
587+
#endif
585588
#endif
586589

587590
#ifdef __cplusplus

0 commit comments

Comments
 (0)