Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/no-malloc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: No Malloc Tests

# START OF COMMON SECTION
Expand Down Expand Up @@ -59,6 +59,17 @@
run: |
cat > "$RUNNER_TEMP/no-malloc-configs.json" <<'EOF'
[
{"name": "opensslextra-staticmemory", "minutes": 2.0,
"configure": ["--enable-opensslextra", "--enable-staticmemory",
"CFLAGS=-DWOLFSSL_NO_MALLOC -DWOLFSSL_TEST_CERT -DUSE_CERT_BUFFERS_2048 -DUSE_CERT_BUFFERS_256 -pedantic -Wdeclaration-after-statement -Wnull-dereference -DTEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE"],
"check": false,
"run": [["./wolfcrypt/test/testwolfcrypt"]]},
{"name": "cryptonly-opensslextra-embedded", "minutes": 1.2,
"configure": ["--enable-cryptonly", "--enable-opensslextra",
"--enable-staticmemory",
"CFLAGS=-DWOLFSSL_NO_MALLOC -DBENCH_EMBEDDED -pedantic -Wdeclaration-after-statement -Wnull-dereference -DTEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE"],
"check": false,
"run": [["./wolfcrypt/test/testwolfcrypt"]]},
{"name": "rsa-keygen", "minutes": 0.8,
"configure": ["--enable-rsa", "--enable-keygen", "--disable-dh",
"CFLAGS=-DWOLFSSL_NO_MALLOC -DRSA_MIN_SIZE=1024 -pedantic -Wdeclaration-after-statement -Wnull-dereference -DTEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE"],
Expand Down
13 changes: 13 additions & 0 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3465,6 +3465,12 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
err_sys("unable to load static memory");
}

#if defined(WOLFSSL_NO_MALLOC) && !defined(NO_MAIN_DRIVER)
/* only the standalone program may publish a pool of its own */
if (wolfSSL_GetGlobalHeapHint() == NULL)
wolfSSL_SetGlobalHeapHint(heap);
#endif

#if defined(WOLFSSL_STATIC_MEMORY) && \
defined(WOLFSSL_STATIC_MEMORY_DEBUG_CALLBACK)
wolfSSL_SetDebugMemoryCb(ExampleDebugMemoryCb);
Expand Down Expand Up @@ -5156,6 +5162,13 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
(void) useVerifyCb;
(void) customVerifyCert;

#if defined(WOLFSSL_STATIC_MEMORY) && defined(WOLFSSL_NO_MALLOC) && \
!defined(NO_MAIN_DRIVER)
/* the pool backing the hint is on this function's stack */
if (wolfSSL_GetGlobalHeapHint() == (void*)heap)
wolfSSL_SetGlobalHeapHint(NULL);
#endif

WOLFSSL_RETURN_FROM_THREAD(0);
}

Expand Down
24 changes: 21 additions & 3 deletions examples/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
WOLFSSL_MEM_STATS mem_stats;
#endif
#endif
WOLFSSL_HEAP_HINT *heap = NULL;
#endif
#if defined(WOLFSSL_TLS13) && defined(HAVE_SUPPORTED_CURVES)
int onlyKeyShare = 0;
Expand Down Expand Up @@ -2826,9 +2827,19 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
WOLFMEM_IO_POOL_FIXED));
#endif /* DEBUG_WOLFSSL */

if (wolfSSL_CTX_load_static_memory(&ctx, method, memory, sizeof(memory),0,1)
!= WOLFSSL_SUCCESS)
err_sys_ex(catastrophic, "unable to load static memory and create ctx");
if (wc_LoadStaticMemory(&heap, memory, sizeof(memory), 0, 1) != 0)
err_sys_ex(catastrophic, "unable to load static memory");

#if defined(WOLFSSL_NO_MALLOC) && !defined(NO_MAIN_DRIVER)
/* only the standalone program may publish a pool of its own */
if (wolfSSL_GetGlobalHeapHint() == NULL)
wolfSSL_SetGlobalHeapHint(heap);
#endif

if (method != NULL)
ctx = wolfSSL_CTX_new_ex(method(heap), heap);
if (ctx == NULL)
err_sys_ex(catastrophic, "unable to get ctx");

/* load in a buffer for IO */
if (wolfSSL_CTX_load_static_memory(&ctx, NULL, memoryIO, sizeof(memoryIO),
Expand Down Expand Up @@ -4249,6 +4260,13 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
#if defined(WOLFSSL_CALLBACKS) && defined(WOLFSSL_EARLY_DATA)
(void) earlyData;
#endif
#if defined(WOLFSSL_STATIC_MEMORY) && defined(WOLFSSL_NO_MALLOC) && \
!defined(NO_MAIN_DRIVER)
/* the pool backing the hint is on this function's stack */
if (wolfSSL_GetGlobalHeapHint() == (void*)heap)
wolfSSL_SetGlobalHeapHint(NULL);
#endif

WOLFSSL_RETURN_FROM_THREAD(0);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit-mcdc/test_asn_ext_whitebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,7 @@ static void wb_decode_cert_req_version(void) { WB_NOTE("WOLFSSL_CERT_REQ off; sk
* Section 26: ParseCert() RSA public key store [:23263-:23267]
* (best-effort -- see file-header RESIDUAL note for operands 2/3).
* ------------------------------------------------------------------------- */
#if (!defined(WOLFSSL_NO_MALLOC) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
#if (!defined(WC_ASN_NO_HEAP) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
defined(WOLFSSL_DYN_CERT)
static void wb_parse_cert_rsa_pubkey(void)
{
Expand All @@ -2769,7 +2769,7 @@ static void wb_parse_cert_rsa_pubkey(void)
FreeDecodedCert(&cert);
}
#else
static void wb_parse_cert_rsa_pubkey(void) { WB_NOTE("WOLFSSL_NO_MALLOC build; ParseCert copy-out skipped"); }
static void wb_parse_cert_rsa_pubkey(void) { WB_NOTE("WC_ASN_NO_HEAP build; ParseCert copy-out skipped"); }
#endif

/* ------------------------------------------------------------------------- *
Expand Down
13 changes: 8 additions & 5 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -24206,7 +24206,7 @@ static int DecodeCertReq(DecodedCert* cert, int* criticalExt)
int ParseCert(DecodedCert* cert, int type, int verify, void* cm)
{
int ret;
#if (!defined(WOLFSSL_NO_MALLOC) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
#if (!defined(WC_ASN_NO_HEAP) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
defined(WOLFSSL_DYN_CERT)
char* ptr;
#endif
Expand All @@ -24215,9 +24215,9 @@ int ParseCert(DecodedCert* cert, int type, int verify, void* cm)
if (ret < 0)
return ret;

#if (!defined(WOLFSSL_NO_MALLOC) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
#if (!defined(WC_ASN_NO_HEAP) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
defined(WOLFSSL_DYN_CERT)
/* cert->subjectCN not stored as copy of WOLFSSL_NO_MALLOC defined */
/* cert->subjectCN not stored as a copy when there is no allocator */
if (cert->subjectCNLen > 0) {
ptr = (char*)XMALLOC((size_t)cert->subjectCNLen + 1, cert->heap,
DYNAMIC_TYPE_SUBJECT_CN);
Expand All @@ -24230,9 +24230,12 @@ int ParseCert(DecodedCert* cert, int type, int verify, void* cm)
}
#endif

#if (!defined(WOLFSSL_NO_MALLOC) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
/* WC_ASN_NO_HEAP, not WOLFSSL_NO_MALLOC: a static-memory build defines the
* latter but still has an allocator, and StoreKey() copies the non-RSA keys
* on the same condition. Skipping the copy here leaves Signer.publicKey NULL,
* so every chain verify under an RSA CA fails BAD_FUNC_ARG. */
#if (!defined(WC_ASN_NO_HEAP) && !defined(NO_WOLFSSL_CM_VERIFY)) || \
defined(WOLFSSL_DYN_CERT)
/* cert->publicKey not stored as copy if WOLFSSL_NO_MALLOC defined */
if ((cert->keyOID == RSAk
#ifdef WC_RSA_PSS
|| cert->keyOID == RSAPSSk
Expand Down
29 changes: 26 additions & 3 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,18 @@ static WC_MAYBE_UNUSED Aes* test_AesGcmNew(void* heap, int declaredDevId,
#ifdef WOLFSSL_STATIC_MEMORY
#if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
#elif defined(WOLFSSL_NO_MALLOC) && defined(OPENSSL_EXTRA) && \
!defined(WOLFCRYPT_ONLY) && !defined(NO_RSA) && !defined(NO_SHA)
/* No malloc, so the compatibility layer's NULL-heap allocations come
* out of this pool on top of what the algorithm tests need. */
#ifdef BENCH_EMBEDDED
Comment thread
Frauschi marked this conversation as resolved.
#error "openssl_pkey0_test() needs about 1MB of pool, far more \
Comment thread
Frauschi marked this conversation as resolved.
than BENCH_EMBEDDED implies: set WOLFSSL_STATIC_MEMORY_TEST_SZ explicitly"
#elif defined(WOLFSSL_HAVE_FRODOKEM) || defined(WOLFSSL_HAVE_MLDSA)
static byte gTestMemory[2048*1024];
#else
static byte gTestMemory[1024*1024];
#endif
#elif defined(WOLFSSL_HAVE_FRODOKEM)
/* FrodoKEM keys (~44 KB) and decaps matrices (~86 KB) are large. */
static byte gTestMemory[1024*1024];
Expand Down Expand Up @@ -2354,8 +2366,9 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
printf("unable to load static memory.\n");
EXIT_TEST(EXIT_FAILURE);
}
#ifndef OPENSSL_EXTRA
wolfSSL_SetGlobalHeapHint(HEAP_HINT);
#if !defined(OPENSSL_EXTRA) || defined(WOLFSSL_NO_MALLOC)
if (wolfSSL_GetGlobalHeapHint() == NULL)
wolfSSL_SetGlobalHeapHint(HEAP_HINT);
#endif
#endif

Expand Down Expand Up @@ -3591,7 +3604,8 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
#endif

#if defined(WOLFSSL_STATIC_MEMORY) && !defined(OPENSSL_EXTRA)
wolfSSL_SetGlobalHeapHint(NULL);
if (wolfSSL_GetGlobalHeapHint() == HEAP_HINT)
wolfSSL_SetGlobalHeapHint(NULL);
#endif
TEST_PASS("Test complete\n");

Expand Down Expand Up @@ -29695,6 +29709,15 @@ static wc_test_ret_t cert_no_malloc_test(void)
ret = WC_TEST_RET_ENC_NC;
}
}
#elif !defined(NO_WOLFSSL_CM_VERIFY) || defined(WOLFSSL_DYN_CERT)
Comment thread
Frauschi marked this conversation as resolved.
/* With an allocator the RSA key is copied out, so a Signer built from this
* cert keeps a public key of its own. */
if ((ret == 0) && ((cert.pubKeyStored != 1) ||
Comment thread
Frauschi marked this conversation as resolved.
(((wc_ptr_t)cert.publicKey >= (wc_ptr_t)cert.source) &&
((wc_ptr_t)cert.publicKey <
(wc_ptr_t)cert.source + cert.maxIdx)))) {
ret = WC_TEST_RET_ENC_NC;
}
#endif
FreeDecodedCert(&cert);
#endif
Expand Down
Loading