Skip to content

cast to unsigned char before isdigit in ASN1 time parsing#72620

Merged
mergify[bot] merged 2 commits into
project-chip:masterfrom
kali834x:asn1-time-ctype-signed-char
Jun 22, 2026
Merged

cast to unsigned char before isdigit in ASN1 time parsing#72620
mergify[bot] merged 2 commits into
project-chip:masterfrom
kali834x:asn1-time-ctype-signed-char

Conversation

@kali834x

Copy link
Copy Markdown
Contributor

Summary

ImportFrom_ASN1_TIME_string validates the time field with isdigit(p[i]), where p is the CharSpan over the raw notBefore/notAfter bytes of a peer certificate (CHIPCryptoPALOpenSSL passes pNotBefore->data directly). On platforms where char is signed, a time byte with the high bit set arrives as a negative int that is neither a valid unsigned char value nor EOF, which is undefined behavior for the ctype functions (C11 7.4p1) and an out-of-bounds read of the classification table on libc builds that do not pad it for negative indices. The loop is the validation that rejects non-digits, so non-ASCII bytes from an untrusted cert reach it by design. Cast to unsigned char before the call, matching the SafeToLower convention already used in dnssd/TxtFields.cpp.

Related issues

None.

Testing

Added a high-bit-byte (0xE9) row to the ASN1UniversalTime error-case table in TestASN1.cpp; it is rejected with ASN1_ERROR_INVALID_ENCODING and exercises the call with a value that is well-defined only after the cast.

@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 updates ASN1UniversalTime::ImportFrom_ASN1_TIME_string to cast characters to unsigned char before passing them to isdigit, preventing potential undefined behavior or assertion failures when handling high-bit characters. A test case with a high-bit byte (0xE9) has also been added to verify correct rejection. There are no review comments, so I have no feedback to provide.

Comment thread src/lib/asn1/tests/TestASN1.cpp Outdated
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

PR #72620: Size comparison from 186f92c to 153cb52

Full report (35 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, psoc6, qpg, realtek, stm32, telink)
platform target config section 186f92c 153cb52 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1094860 1094860 0 0.0
RAM 144882 144882 0 0.0
bl616 lighting-app bl616+thread FLASH 1106172 1106172 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1593968 1593968 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1057834 1057834 0 0.0
RAM 108525 108525 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 896508 896508 0 0.0
RAM 105908 105908 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 777336 777336 0 0.0
RAM 103404 103404 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 790088 790088 0 0.0
RAM 108684 108684 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 739336 739336 0 0.0
RAM 97612 97612 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 719508 719508 0 0.0
RAM 97644 97644 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 569638 569638 0 0.0
RAM 205112 205112 0 0.0
lock CC3235SF_LAUNCHXL FLASH 597190 597190 0 0.0
RAM 205272 205272 0 0.0
efr32 lighting-app BRD4187C FLASH 1094988 1094988 0 0.0
RAM 135256 135256 0 0.0
lock-app BRD4187C FLASH 994816 994816 0 0.0
RAM 131292 131292 0 0.0
BRD4338a FLASH 799857 799857 0 0.0
RAM 243432 243432 0 0.0
esp32 all-clusters-app c3devkit DRAM 99876 99876 0 0.0
FLASH 1624510 1624510 0 0.0
IRAM 94776 94776 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 835056 835056 0 0.0
RAM 157693 157693 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1737916 1737916 0 0.0
RAM 215412 215412 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1626596 1626596 0 0.0
RAM 211604 211604 0 0.0
light cy8ckit_062s2_43012 FLASH 1470908 1470908 0 0.0
RAM 197436 197436 0 0.0
lock cy8ckit_062s2_43012 FLASH 1504356 1504356 0 0.0
RAM 225268 225268 0 0.0
qpg lighting-app qpg6200+debug FLASH 843060 843060 0 0.0
RAM 127908 127908 0 0.0
lock-app qpg6200+debug FLASH 782960 782960 0 0.0
RAM 118840 118840 0 0.0
realtek light-switch-app rtl8777g FLASH 689296 689296 0 0.0
RAM 101780 101780 0 0.0
lighting-app rtl8777g FLASH 730248 730248 0 0.0
RAM 102052 102052 0 0.0
stm32 light STM32WB5MM-DK FLASH 478940 478940 0 0.0
RAM 141492 141492 0 0.0
telink all-devices-app tl7218x FLASH 834320 834320 0 0.0
RAM 99028 99028 0 0.0
tlsr9118bdk40d FLASH 625688 625688 0 0.0
RAM 120160 120160 0 0.0
bridge-app tl7218x FLASH 734108 734108 0 0.0
RAM 97700 97700 0 0.0
light-app-ota-compress-lzma-factory-data tl3218x FLASH 800638 800638 0 0.0
RAM 42380 42380 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl7218x FLASH 845778 845778 0 0.0
RAM 101492 101492 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 734598 734598 0 0.0
RAM 57816 57816 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 795660 795660 0 0.0
RAM 75176 75176 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 734514 734514 0 0.0
RAM 34472 34472 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 615170 615170 0 0.0
RAM 118508 118508 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 841726 841730 4 0.0
RAM 97376 97376 0 0.0

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.19%. Comparing base (186f92c) to head (31411bc).
⚠️ Report is 36 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #72620      +/-   ##
==========================================
+ Coverage   56.06%   56.19%   +0.12%     
==========================================
  Files        1640     1644       +4     
  Lines      112563   113050     +487     
  Branches    13350    13361      +11     
==========================================
+ Hits        63110    63529     +419     
- Misses      49453    49521      +68     

☔ 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.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

PR #72620: Size comparison from 186f92c to 31411bc

Increases above 0.2%:

platform target config section 186f92c 31411bc change % change
telink all-devices-app tl7218x FLASH 834320 843418 9098 1.1
tlsr9118bdk40d FLASH 625688 634784 9096 1.5
Full report (35 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, psoc6, qpg, realtek, stm32, telink)
platform target config section 186f92c 31411bc change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1094860 1094778 -82 -0.0
RAM 144882 144882 0 0.0
bl616 lighting-app bl616+thread FLASH 1106172 1106092 -80 -0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1593968 1593888 -80 -0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1057834 1057752 -82 -0.0
RAM 108525 108525 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 896508 896426 -82 -0.0
RAM 105908 105908 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 777336 777288 -48 -0.0
RAM 103404 103404 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 790088 790032 -56 -0.0
RAM 108684 108684 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 739336 739280 -56 -0.0
RAM 97612 97612 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 719508 719452 -56 -0.0
RAM 97644 97644 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 569638 569582 -56 -0.0
RAM 205112 205112 0 0.0
lock CC3235SF_LAUNCHXL FLASH 597190 597134 -56 -0.0
RAM 205272 205272 0 0.0
efr32 lighting-app BRD4187C FLASH 1094988 1094828 -160 -0.0
RAM 135256 135256 0 0.0
lock-app BRD4187C FLASH 994816 994752 -64 -0.0
RAM 131292 131292 0 0.0
BRD4338a FLASH 799857 799713 -144 -0.0
RAM 243432 243432 0 0.0
esp32 all-clusters-app c3devkit DRAM 99876 99884 8 0.0
FLASH 1624510 1624662 152 0.0
IRAM 94776 94776 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 835056 835156 100 0.0
RAM 157693 157704 11 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1737916 1737908 -8 -0.0
RAM 215412 215420 8 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1626596 1626452 -144 -0.0
RAM 211604 211604 0 0.0
light cy8ckit_062s2_43012 FLASH 1470908 1470764 -144 -0.0
RAM 197436 197436 0 0.0
lock cy8ckit_062s2_43012 FLASH 1504356 1504212 -144 -0.0
RAM 225268 225268 0 0.0
qpg lighting-app qpg6200+debug FLASH 843060 843012 -48 -0.0
RAM 127908 127908 0 0.0
lock-app qpg6200+debug FLASH 782960 782896 -64 -0.0
RAM 118840 118840 0 0.0
realtek light-switch-app rtl8777g FLASH 689296 689248 -48 -0.0
RAM 101780 101780 0 0.0
lighting-app rtl8777g FLASH 730248 730192 -56 -0.0
RAM 102052 102052 0 0.0
stm32 light STM32WB5MM-DK FLASH 478940 478900 -40 -0.0
RAM 141492 141492 0 0.0
telink all-devices-app tl7218x FLASH 834320 843418 9098 1.1
RAM 99028 99092 64 0.1
tlsr9118bdk40d FLASH 625688 634784 9096 1.5
RAM 120160 120224 64 0.1
bridge-app tl7218x FLASH 734108 734038 -70 -0.0
RAM 97700 97700 0 0.0
light-app-ota-compress-lzma-factory-data tl3218x FLASH 800638 800568 -70 -0.0
RAM 42380 42380 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl7218x FLASH 845778 845708 -70 -0.0
RAM 101492 101492 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 734598 734528 -70 -0.0
RAM 57816 57816 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 795660 795590 -70 -0.0
RAM 75176 75176 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 734514 734444 -70 -0.0
RAM 34472 34472 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 615170 615100 -70 -0.0
RAM 118508 118508 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 841726 841660 -66 -0.0
RAM 97376 97376 0 0.0

@andy31415 andy31415 added the sdk-maintainer-approved PR marked by `matter-sdk-maintainers` as suitable for MERGE - meets guideline & sufficient reviews. label Jun 22, 2026
@mergify mergify Bot merged commit 66689f5 into project-chip:master Jun 22, 2026
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib review - pending sdk-maintainer-approved PR marked by `matter-sdk-maintainers` as suitable for MERGE - meets guideline & sufficient reviews.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants