Skip to content

Fix: Test memory leak and Failing test when md5 and sha are enabled - #11025

Open
aidankeefe2022 wants to merge 2 commits into
wolfSSL:masterfrom
aidankeefe2022:test-fix-for-md5-and-sha-enabled
Open

Fix: Test memory leak and Failing test when md5 and sha are enabled#11025
aidankeefe2022 wants to merge 2 commits into
wolfSSL:masterfrom
aidankeefe2022:test-fix-for-md5-and-sha-enabled

Conversation

@aidankeefe2022

Copy link
Copy Markdown
Member

Description

Fixed a memory leak where if _ret is already failing, the rngInit function will not run, causing rngFree to free garbage data. The fix was to have rngInit always run to match with rngFree by swapping ExpectInt to DoExpectInt. Fixed failing test where WC_SIG_MIN_HASH_TYPE was not properly set for --enable-sha and --enable-md5, so we skip under those conditions.

Found while testing wolfCLU

Testing

Code no longer leaks, and code no longer fails with the wrong code for the test when SHA and MD5 are enabled

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 181,092 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +64 B (+0.0%, 771,412 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pq

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐺 Skoll Code Review

Overall recommendation: APPROVE
Findings: 6 total — 2 posted, 4 skipped

Posted findings

  • [Medium] Weak-hash guard is skipped even when WC_SIG_MIN_HASH_TYPE raises the floor, and silently self-destructs if the default ever moves into a headertests/api/test_signature.c:338
  • [Medium] Lowered-floor branch of wc_SignatureCheckHashStrength() has no coverage at alltests/api/test_signature.c:338
Skipped findings
  • [Low] PR description attributes the failure to --enable-sha/--enable-md5, but the trigger is --enable-wolfclu
  • [Low] Two different init/free-pairing conventions now coexist in this file
  • [Low] Weak-hash assertions skipped for any WC_SIG_MIN_HASH_TYPE override, including stronger floors
  • [Info] Guard depends on WC_SIG_MIN_HASH_TYPE's default living in signature.c, not a public header

Review generated by Skoll via Claude/Codex

Comment thread tests/api/test_signature.c Outdated
#ifndef NO_SHA
/* Hash weaker than WC_SIG_MIN_HASH_TYPE (default SHA-256)
* rejected by wc_SignatureCheckHashStrength() */
#if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [Medium] Weak-hash guard is skipped even when WC_SIG_MIN_HASH_TYPE raises the floor, and silently self-destructs if the default ever moves into a header
💡 SUGGEST test

The new guard #if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE) drops the SHA-1-rejection assertion whenever the macro is defined at all, not just when it is defined to something weaker than SHA-256. If a downstream config sets WC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_SHA384 (a stricter floor), wc_SignatureCheckHashStrength() still rejects SHA-1 with BAD_FUNC_ARG, but the test is skipped anyway — coverage is lost for no reason.

There is a second, more fragile coupling. The default #ifndef WC_SIG_MIN_HASH_TYPE / #define WC_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256 / #endif currently lives in wolfcrypt/src/signature.c:62-64, not in wolfssl/wolfcrypt/signature.h. The test only compiles the assertion because that default is invisible to this translation unit. The moment anyone moves that default into signature.h (a natural refactor — signature.h is included at line 31 of this file, before the guard), WC_SIG_MIN_HASH_TYPE becomes defined in every build and both assertion blocks become permanently dead code, with no compile error and no test failure to signal it.

A size comparison against the configured floor keeps coverage in every config and removes the dependence on where the default happens to be defined.

Suggestion:

Suggested change
#if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE)
/* Near the top of the file, mirroring wolfcrypt/src/signature.c: */
#ifndef WC_SIG_MIN_HASH_TYPE
#define TEST_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256
#else
#define TEST_SIG_MIN_HASH_TYPE WC_SIG_MIN_HASH_TYPE
#endif
/* At the call site: */
#ifndef NO_SHA
/* Hash weaker than WC_SIG_MIN_HASH_TYPE is rejected by
* wc_SignatureCheckHashStrength(). wolfCLU with MD5 compiled in
* lowers the floor to MD5, which lets SHA-1 through. */
if (wc_HashGetDigestSize(TEST_SIG_MIN_HASH_TYPE) >
WC_SHA_DIGEST_SIZE) {
ExpectIntEQ(wc_SignatureVerify(WC_HASH_TYPE_SHA, sig_type,
data, data_len, sig, sig_len, &ecc, key_len),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
}
#endif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged the two issues into one fix

Comment thread tests/api/test_signature.c Outdated
#ifndef NO_SHA
/* Hash weaker than WC_SIG_MIN_HASH_TYPE (default SHA-256)
* rejected by wc_SignatureCheckHashStrength() */
#if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [Medium] Lowered-floor branch of wc_SignatureCheckHashStrength() has no coverage at all
💡 SUGGEST test

Both new guards are bare #if ... #endif with no #else. In exactly the configuration that motivated this PR (wolfCLU with MD5, which sets -DWC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_MD5 at configure.ac:12052), the test now asserts nothing about hash-strength enforcement — it does not verify that SHA-1 is accepted under the lowered floor, only that it is no longer checked.

That matters because this file is explicitly a decision-coverage suite (see the header comment at lines 209-227 about independence pairs). Silently skipping the only assertion that touches wc_SignatureCheckHashStrength() means a regression that made the floor unconditionally SHA-256 — breaking wolfCLU's MD5 support, which is precisely the behaviour this override exists to preserve — would not be caught by any test.

Suggestion:

Suggested change
#if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE)
#if !defined(NO_SHA) && !defined(WC_SIG_MIN_HASH_TYPE)
ExpectIntEQ(wc_SignatureVerify(WC_HASH_TYPE_SHA, sig_type,
data, data_len, sig, sig_len, &ecc, key_len),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#elif !defined(NO_SHA)
/* Floor lowered (e.g. wolfCLU with MD5): SHA-1 must get past the
* strength check and fail on the signature itself instead. */
ExpectIntNE(wc_SignatureVerify(WC_HASH_TYPE_SHA, sig_type,
data, data_len, sig, sig_len, &ecc, key_len),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#endif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged the two issues into one fix

@aidankeefe2022

Copy link
Copy Markdown
Member Author

Retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants