Fix Coverity DEADCODE findings in COSE MAC and CBOR decode paths#58
Merged
Merged
Conversation
1a72eda to
055612c
Compare
055612c to
be99c6e
Compare
mattia-moffa
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves four Coverity Scan DEADCODE defects and re-adds the Coverity Scan badge to the README.
Coverity fixes
wc_CoseMac_Create) and CID 1695272 (wc_CoseMac_Verify): the HMAC dispatch block freed theHmacand resethmacInited = 0in-block, making the function-end cleanupif (hmacInited != 0)unreachable. Removed the redundant in-block free so the single function-end cleanup is the sole reachable free path — matching the existingwc_CoseMac0_Createidiom.wc_CoseMac0_Create): themacPayload == NULL && macPayloadLen > 0guard is unreachable because the all-NULL payload/detached pair is already rejected above, somacPayloadis always non-NULL on success. Removed the dead check.wolfCose_CBOR_DecodeHead): the bstr/tstr length checkitem->val > (uint64_t)SIZE_MAXis dead on 64-bit targets whereSIZE_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 asize_ttruncation 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.