Skip to content

Apply AI-generated patch for unchecked nullable dereferences in JFDS#73096

Open
apahl-cl wants to merge 2 commits into
project-chip:masterfrom
apahl-cl:jfds-null-derefs
Open

Apply AI-generated patch for unchecked nullable dereferences in JFDS#73096
apahl-cl wants to merge 2 commits into
project-chip:masterfrom
apahl-cl:jfds-null-derefs

Conversation

@apahl-cl

Copy link
Copy Markdown
Contributor

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/TestJointFabricDatastore

The newly added tests will only pass if the patch is applied to JointFabricDatastore.cpp.

@gemini-code-assist gemini-code-assist Bot 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.

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));

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

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));

@apahl-cl apahl-cl added the request-backport-supported Request to backport/CP to latest supported branches (usually LTS + latest certifiable release) label Jul 16, 2026
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

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)
platform target config section 517b1a10 ac1b55f change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1099930 1099930 0 0.0
RAM 133546 133546 0 0.0
bl702 lighting-app bl702+eth FLASH 1086740 1086740 0 0.0
RAM 109157 109157 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 882822 882822 0 0.0
RAM 108628 108628 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 778840 778840 0 0.0
RAM 103524 103524 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 790972 790972 0 0.0
RAM 108708 108708 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 740076 740076 0 0.0
RAM 97636 97636 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 720240 720240 0 0.0
RAM 97668 97668 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 570258 570258 0 0.0
RAM 205136 205136 0 0.0
lock CC3235SF_LAUNCHXL FLASH 597818 597818 0 0.0
RAM 205296 205296 0 0.0
efr32 lighting-app BRD4187C FLASH 1120452 1120452 0 0.0
RAM 135124 135124 0 0.0
lock-app BRD4187C FLASH 1010892 1010892 0 0.0
RAM 131408 131408 0 0.0
BRD4338a FLASH 809193 809193 0 0.0
RAM 235252 235252 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 848268 848268 0 0.0
RAM 157999 157999 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1756364 1756364 0 0.0
RAM 215716 215716 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1627548 1627548 0 0.0
RAM 211628 211628 0 0.0
light cy8ckit_062s2_43012 FLASH 1472156 1472156 0 0.0
RAM 197556 197556 0 0.0
lock cy8ckit_062s2_43012 FLASH 1504972 1504972 0 0.0
RAM 225292 225292 0 0.0
qpg lighting-app qpg6200+debug FLASH 843712 843712 0 0.0
RAM 127932 127932 0 0.0
lock-app qpg6200+debug FLASH 783500 783500 0 0.0
RAM 118864 118864 0 0.0
realtek light-switch-app rtl8777g FLASH 690648 690648 0 0.0
RAM 101896 101896 0 0.0
lighting-app rtl8777g FLASH 731464 731464 0 0.0
RAM 102176 102176 0 0.0
stm32 light STM32WB5MM-DK FLASH 479740 479740 0 0.0
RAM 141612 141612 0 0.0
telink all-devices-app tl7218x FLASH 897826 897826 0 0.0
RAM 100044 100044 0 0.0
tlsr9118bdk40d FLASH 689340 689340 0 0.0
RAM 121176 121176 0 0.0
bridge-app tl7218x FLASH 735338 735338 0 0.0
RAM 97724 97724 0 0.0
light-app-ota-compress-lzma-factory-data tl3218x FLASH 802084 802084 0 0.0
RAM 42496 42496 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl7218x FLASH 847354 847354 0 0.0
RAM 101608 101608 0 0.0
light-switch-app-ota tl3218x_retention FLASH 736220 736220 0 0.0
RAM 33720 33720 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 744412 744412 0 0.0
RAM 57948 57948 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 805500 805500 0 0.0
RAM 75300 75300 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 616570 616570 0 0.0
RAM 118624 118624 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 843566 843570 4 0.0
RAM 97492 97492 0 0.0

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

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)
platform target config section d17f626 bc3cf4e change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1099930 1099930 0 0.0
RAM 133546 133546 0 0.0
bl702 lighting-app bl702+eth FLASH 1086740 1086740 0 0.0
RAM 109157 109157 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 882822 882822 0 0.0
RAM 108628 108628 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 778840 778840 0 0.0
RAM 103524 103524 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 790972 790972 0 0.0
RAM 108708 108708 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 740076 740076 0 0.0
RAM 97636 97636 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 720240 720240 0 0.0
RAM 97668 97668 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 570258 570258 0 0.0
RAM 205136 205136 0 0.0
lock CC3235SF_LAUNCHXL FLASH 597818 597818 0 0.0
RAM 205296 205296 0 0.0
efr32 lighting-app BRD4187C FLASH 1120452 1120452 0 0.0
RAM 135124 135124 0 0.0
lock-app BRD4187C FLASH 1010892 1010892 0 0.0
RAM 131408 131408 0 0.0
BRD4338a FLASH 809193 809193 0 0.0
RAM 235252 235252 0 0.0
esp32 all-clusters-app c3devkit DRAM 99628 99628 0 0.0
FLASH 1629286 1629286 0 0.0
IRAM 94776 94776 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 848268 848268 0 0.0
RAM 157999 157999 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1756364 1756364 0 0.0
RAM 215716 215716 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1627548 1627548 0 0.0
RAM 211628 211628 0 0.0
light cy8ckit_062s2_43012 FLASH 1472156 1472156 0 0.0
RAM 197556 197556 0 0.0
lock cy8ckit_062s2_43012 FLASH 1504972 1504972 0 0.0
RAM 225292 225292 0 0.0
qpg lighting-app qpg6200+debug FLASH 843712 843712 0 0.0
RAM 127932 127932 0 0.0
lock-app qpg6200+debug FLASH 783500 783500 0 0.0
RAM 118864 118864 0 0.0
realtek light-switch-app rtl8777g FLASH 690648 690648 0 0.0
RAM 101896 101896 0 0.0
lighting-app rtl8777g FLASH 731464 731464 0 0.0
RAM 102176 102176 0 0.0
stm32 light STM32WB5MM-DK FLASH 479740 479740 0 0.0
RAM 141612 141612 0 0.0
telink all-devices-app tl7218x FLASH 897826 897826 0 0.0
RAM 100044 100044 0 0.0
tlsr9118bdk40d FLASH 689340 689340 0 0.0
RAM 121176 121176 0 0.0
bridge-app tl7218x FLASH 735338 735338 0 0.0
RAM 97724 97724 0 0.0
light-app-ota-compress-lzma-factory-data tl3218x FLASH 802084 802084 0 0.0
RAM 42496 42496 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl7218x FLASH 847354 847354 0 0.0
RAM 101608 101608 0 0.0
light-switch-app-ota tl3218x_retention FLASH 736220 736220 0 0.0
RAM 33720 33720 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 744412 744412 0 0.0
RAM 57948 57948 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 805500 805500 0 0.0
RAM 75300 75300 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 616570 616570 0 0.0
RAM 118624 118624 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 843566 843570 4 0.0
RAM 97492 97492 0 0.0

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.03%. Comparing base (d17f626) to head (bc3cf4e).

Files with missing lines Patch % Lines
src/app/server/JointFabricDatastore.cpp 50.00% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

app request-backport-supported Request to backport/CP to latest supported branches (usually LTS + latest certifiable release) review - pending

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant