Skip to content

Fix Coverity DEADCODE findings in COSE MAC and CBOR decode paths#58

Merged
mattia-moffa merged 1 commit into
wolfSSL:mainfrom
aidangarske:fix-coverity-deadcode
Jun 23, 2026
Merged

Fix Coverity DEADCODE findings in COSE MAC and CBOR decode paths#58
mattia-moffa merged 1 commit into
wolfSSL:mainfrom
aidangarske:fix-coverity-deadcode

Conversation

@aidangarske

@aidangarske aidangarske commented Jun 23, 2026

Copy link
Copy Markdown
Member

Resolves four Coverity Scan DEADCODE defects and re-adds the Coverity Scan badge to the README.

Coverity fixes

  • CID 1695273 (wc_CoseMac_Create) and CID 1695272 (wc_CoseMac_Verify): the HMAC dispatch block freed the Hmac and reset hmacInited = 0 in-block, making the function-end cleanup if (hmacInited != 0) unreachable. Removed the redundant in-block free so the single function-end cleanup is the sole reachable free path — matching the existing wc_CoseMac0_Create idiom.
  • CID 1695271 (wc_CoseMac0_Create): the macPayload == NULL && macPayloadLen > 0 guard is unreachable because the all-NULL payload/detached pair is already rejected above, so macPayload is always non-NULL on success. Removed the dead check.
  • CID 1690648 (wolfCose_CBOR_DecodeHead): the bstr/tstr length check item->val > (uint64_t)SIZE_MAX is dead on 64-bit targets where SIZE_MAX == UINT64_MAX. Reworked the bounds check to compare the 64-bit CBOR length directly against the remaining buffer bytes (item->val > (uint64_t)(ctx->bufSz - ctx->idx)), which rejects any oversize length as malformed on every platform without a size_t truncation hazard — eliminating the dead branch with no preprocessor identifier comparison (keeps MISRA Rule 20.9 clean).

README

Added the Coverity Scan build-status badge ahead of the existing CI/Skoll/Fenrir badges.

Testing

  • make clean && make && make test — all tests pass.
  • cppcheck --addon=misra — no Rule 20.9 (or other new) violations.

@aidangarske aidangarske force-pushed the fix-coverity-deadcode branch from 1a72eda to 055612c Compare June 23, 2026 01:12
@aidangarske aidangarske requested a review from mattia-moffa June 23, 2026 01:15
@aidangarske aidangarske added bug Something isn't working fix labels Jun 23, 2026
@aidangarske aidangarske force-pushed the fix-coverity-deadcode branch from 055612c to be99c6e Compare June 23, 2026 01:21
@mattia-moffa mattia-moffa merged commit c665f32 into wolfSSL:main Jun 23, 2026
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants