Apply AI-generated patch for unchecked nullable dereferences in JFDS#73096
Apply AI-generated patch for unchecked nullable dereferences in JFDS#73096apahl-cl wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a potential crash in JointFabricDatastore::UpdateGroup by ensuring that groupKeySetID, groupCAT, and groupCATVersion are checked for null before calling .Value(). It also adds corresponding regression tests. The review feedback points out a type mismatch in the test code where groupCAT is cast to uint16_t instead of uint32_t, which could lead to truncation.
|
|
||
| JointFabricCluster::Commands::UpdateGroup::DecodableType updateGroup; | ||
| updateGroup.groupID = 11; | ||
| updateGroup.groupCAT.SetNonNull(static_cast<uint16_t>(0x1234)); |
There was a problem hiding this comment.
The groupCAT field represents a CASE Authenticated Tag (CAT), which is a 32-bit value (uint32_t / chip::CATId). Casting it to uint16_t is a type mismatch and can lead to silent truncation if a 32-bit CAT value is used in the future. Please cast it to uint32_t instead.
updateGroup.groupCAT.SetNonNull(static_cast<uint32_t>(0x1234));|
PR #73096: Size comparison from 517b1a1 to ac1b55f Full report (32 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, nrfconnect, psoc6, qpg, realtek, stm32, telink)
|
|
PR #73096: Size comparison from d17f626 to bc3cf4e Full report (33 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, psoc6, qpg, realtek, stm32, telink)
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #73096 +/- ##
==========================================
+ Coverage 57.01% 57.03% +0.02%
==========================================
Files 1655 1655
Lines 114161 114164 +3
Branches 13229 13213 -16
==========================================
+ Hits 65084 65116 +32
+ Misses 49077 49048 -29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
We add null checks to various Optional derefs in JointFabricDatastore.cpp. Also, this PR includes unit tests that catch scenarios where the unchecked derefs would cause a crash. With the null checks in place, no crash will occur.
AI disclosure: this patch was AI generated, but the problem and fix were manually reviewed.
Related issues
#71880 is similar, but it seems like the cited derefs are no longer present after some reworks in joint-fabric-datastore-server.cpp.
I looked for additional unsafe derefs in JFDS code and couldn't find any.
Testing
source scripts/activate.sh ninja -C out/linux-x64-tests-asan-clang tests/TestJointFabricDatastore ./out/linux-x64-tests-asan-clang/tests/TestJointFabricDatastoreThe newly added tests will only pass if the patch is applied to JointFabricDatastore.cpp.