@@ -772,6 +772,11 @@ typedef struct testVector {
772772#ifndef WC_TEST_EXPORT_SUBTESTS
773773
774774WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void);
775+ /* Under NO_INLINE, ForceZero() is WOLFSSL_LOCAL (hidden visibility) inside
776+ * libwolfssl and unreachable from this separate test binary. */
777+ #if !defined(WOLFSSL_NO_FORCE_ZERO) && !defined(NO_INLINE)
778+ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t forcezero_test(void);
779+ #endif
775780WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
776781WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
777782WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
@@ -2409,6 +2414,13 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
24092414 else
24102415 TEST_PASS("macro test passed!\n");
24112416
2417+ #if !defined(WOLFSSL_NO_FORCE_ZERO) && !defined(NO_INLINE)
2418+ if ( (ret = forcezero_test()) != 0)
2419+ TEST_FAIL("forcezero test failed!\n", ret);
2420+ else
2421+ TEST_PASS("forcezero test passed!\n");
2422+ #endif
2423+
24122424 if ( (ret = error_test()) != 0)
24132425 TEST_FAIL("error test failed!\n", ret);
24142426 else
@@ -4097,6 +4109,47 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t macro_test(void)
40974109 return ret;
40984110}
40994111
4112+ /* Under NO_INLINE, ForceZero() is WOLFSSL_LOCAL (hidden visibility) inside
4113+ * libwolfssl and unreachable from this separate test binary. */
4114+ #if !defined(WOLFSSL_NO_FORCE_ZERO) && !defined(NO_INLINE)
4115+ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t forcezero_test(void)
4116+ {
4117+ /* Test unaligned offsets and lengths. Oversized buffer prevents OOB writes. */
4118+ byte buf[64];
4119+ static const size_t offsets[] = { 0, 1, 2, 3, 7 };
4120+ static const size_t lens[] = { 0, 1, 3, 7, 8, 9, 16, 31 };
4121+ size_t oi, li;
4122+ ForceZero(NULL, 0);
4123+
4124+ for (oi = 0; oi < XELEM_CNT(offsets); oi++) {
4125+ for (li = 0; li < XELEM_CNT(lens); li++) {
4126+ size_t off = offsets[oi];
4127+ size_t len = lens[li];
4128+ size_t i;
4129+
4130+ XMEMSET(buf, 0xA5, sizeof(buf));
4131+ ForceZero(buf + off, len);
4132+
4133+ for (i = 0; i < len; i++) {
4134+ if (buf[off + i] != 0x00)
4135+ return WC_TEST_RET_ENC_NC;
4136+ }
4137+ /* bytes outside [off, off+len) must be untouched */
4138+ for (i = 0; i < off; i++) {
4139+ if (buf[i] != (byte)0xA5)
4140+ return WC_TEST_RET_ENC_NC;
4141+ }
4142+ for (i = off + len; i < sizeof(buf); i++) {
4143+ if (buf[i] != (byte)0xA5)
4144+ return WC_TEST_RET_ENC_NC;
4145+ }
4146+ }
4147+ }
4148+
4149+ return 0;
4150+ }
4151+ #endif
4152+
41004153WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void)
41014154{
41024155 const char* errStr;
0 commit comments