cast to unsigned char before isdigit in ASN1 time parsing#72620
Conversation
There was a problem hiding this comment.
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.
|
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)
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
PR #72620: Size comparison from 186f92c to 31411bc Increases above 0.2%:
Full report (35 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, psoc6, qpg, realtek, stm32, telink)
|
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.