Conversation
…est.h, wolfssl/wolfcrypt/wc_port.h: fixes and workarounds for clang-tidy complaints: * clang-diagnostic-unknown-warning-option * bugprone-sizeof-expression * clang-diagnostic-error "address argument to atomic operation must be a pointer to a trivially-copyable type" * bugprone-macro-parentheses * clang-diagnostic-unused-but-set-variable * readability-redundant-declaration
…eyDecode() and wc_EccPublicKeyDecode(), detected by cppcheck-force-source, lms-xmss-wolfssl-all-clang-sanitizer, and sanitizer-clang-all-noasm.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10086
Scan targets checked: linuxkm-bugs, linuxkm-src, wolfcrypt-bugs, wolfcrypt-src
Findings: 2
High (1)
Wrong argument type passed to FREE_ASNGETDATA in wc_EccPublicKeyDecode
File: wolfcrypt/src/asn.c:30214
Function: wc_EccPublicKeyDecode
Category: API contract violations
The call FREE_ASNGETDATA(dataASN, key) passes key (an ecc_key* pointer) as the second argument, but the macro expects a heap pointer (the same type as the 4th argument to ALLOC_ASNGETDATA). The corresponding allocation on the same function uses key->heap: ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap). The original code correctly passed key->heap. When WOLFSSL_SMALL_STACK is defined, FREE_ASNGETDATA expands to XFREE(dataASN, heap, DYNAMIC_TYPE_TMP_BUFFER) — passing an ecc_key* where a heap hint is expected would result in incorrect behavior or memory corruption.
FREE_ASNGETDATA(dataASN, key);
return ret;Recommendation: Restore the original heap argument: FREE_ASNGETDATA(dataASN, key->heap);
Low (1)
Potentially incorrect heap argument in FREE_ASNGETDATA
File: wolfcrypt/src/asn.c:30214
Function: wc_EccPublicKeyDecode
Category: Cryptographic correctness
The second argument to FREE_ASNGETDATA was changed from key->heap to key. The corresponding ALLOC_ASNGETDATA call still uses key->heap as the heap parameter: ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap). If FREE_ASNGETDATA passes its second argument directly to XFREE as the heap identifier, passing key (an ecc_key* pointer) instead of key->heap (a void* heap pointer) would supply the wrong value. With custom memory allocators that inspect the heap parameter, this could cause incorrect deallocation behavior. Note: if the FREE_ASNGETDATA macro was updated elsewhere to extract ->heap from the key object, this change is correct — the reviewer could not access the macro definition to confirm.
- FREE_ASNGETDATA(dataASN, key->heap);
+ FREE_ASNGETDATA(dataASN, key);Recommendation: Verify that the FREE_ASNGETDATA macro definition accepts a key struct pointer and correctly extracts the heap. If it still expects a raw heap pointer, revert to FREE_ASNGETDATA(dataASN, key->heap) to match the ALLOC_ASNGETDATA call.
This review was generated automatically by Fenrir. Findings are non-blocking.
…REE_ASNGETDATA(dataASN, key->heap).
|
retest this please |
fixed |
|
retest this please |
|
Note, the OpenVPN failure is reporting defects in OpenVPN, not in libwolfssl. Ignore for now. |
linuxkm/,wolfcrypt/src/dh.c,wolfcrypt/test/test.c,wolfcrypt/test/test.h,wolfssl/wolfcrypt/wc_port.h:fixes and workarounds for clang-tidy complaints:
clang-diagnostic-unknown-warning-optionbugprone-sizeof-expressionclang-diagnostic-error"address argument to atomic operation must be a pointer to a trivially-copyable type"bugprone-macro-parenthesesclang-diagnostic-unused-but-set-variablereadability-redundant-declarationwolfcrypt/src/asn.c: fixes for invalid memory access inwc_DsaPublicKeyDecode()andwc_EccPublicKeyDecode(), detected bycppcheck-force-source,lms-xmss-wolfssl-all-clang-sanitizer, andsanitizer-clang-all-noasm.wolfssl/wolfcrypt/types.h: restoreWC_ALLOC_DO_ON_FAILUREfallback definition from 760178c -- reversion in part of 5f4d499. fixes optest build failures inall-crypto-only-intelasm-fips-v5-linuxkm-next-insmod-optest,all-crypto-only-intelasm-fips-v6-linuxkm-next-insmod-optest, andall-crypto-only-intelasm-fips-dev-linuxkm-next-insmod-optest.tested with