Commit 47d5b2c
committed
pkcs7: address second-round review (no-malloc, test guards, hardening)
- Replace the mandatory heap allocation of the signer attribute array with a
hybrid: an inline array (sized MAX_SIGNED_ATTRIBS_SZ, the historical
footprint) is used for the common case with no heap use, and a heap buffer is
allocated only when the attribute count exceeds it. Restores WOLFSSL_NO_MALLOC
support (no allocation in the common path; >inline returns BUFFER_E without a
heap, matching the historical cap) and keeps the per-ESD footprint unchanged.
- wc_PKCS7_GetSignedAttribValue(): reject a value that still carries an outer
SET wrapper (defends against an unexpected decoded shape) and guard the
returned length against INT overflow.
- Multi-certificate decode bound: clamp certSetEnd to pkiMsg2Sz to guard against
overflow/over-long length, and correct the comment about the streaming idx.
- Tests: guard the 3-certificate certs-only and multi-cert tests with
MAX_PKCS7_CERTS >= 3, and the 9-attribute test with
(!WOLFSSL_NO_MALLOC || MAX_SIGNED_ATTRIBS_SZ >= 9), so constrained builds do
not fail spuriously.
- ChangeLog: document the non-streaming multi-certificate decode fix.
Verified across default (streaming), NO_PKCS7_STREAM, and WOLFSSL_SMALL_STACK
builds; pkcs7.c also compiles cleanly with -DWOLFSSL_NO_MALLOC. wolfcrypt and
unit tests pass and valgrind is clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EprPgb9PzJkPp8LXuFk1yR1 parent 546a635 commit 47d5b2c
3 files changed
Lines changed: 99 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | | - | |
1575 | | - | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
1576 | 1583 | | |
1577 | 1584 | | |
1578 | 1585 | | |
| |||
1584 | 1591 | | |
1585 | 1592 | | |
1586 | 1593 | | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
1587 | 1597 | | |
1588 | 1598 | | |
1589 | 1599 | | |
| |||
1671 | 1681 | | |
1672 | 1682 | | |
1673 | 1683 | | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
1679 | 1691 | | |
1680 | 1692 | | |
1681 | 1693 | | |
| |||
3326 | 3338 | | |
3327 | 3339 | | |
3328 | 3340 | | |
3329 | | - | |
3330 | | - | |
| 3341 | + | |
| 3342 | + | |
3331 | 3343 | | |
3332 | | - | |
| 3344 | + | |
| 3345 | + | |
3333 | 3346 | | |
3334 | 3347 | | |
3335 | 3348 | | |
3336 | 3349 | | |
3337 | 3350 | | |
3338 | 3351 | | |
3339 | | - | |
3340 | | - | |
3341 | | - | |
3342 | | - | |
3343 | | - | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
3344 | 3356 | | |
3345 | 3357 | | |
3346 | 3358 | | |
3347 | | - | |
3348 | | - | |
3349 | | - | |
3350 | | - | |
3351 | | - | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
3352 | 3368 | | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
3353 | 3385 | | |
3354 | 3386 | | |
3355 | 3387 | | |
| |||
3783 | 3815 | | |
3784 | 3816 | | |
3785 | 3817 | | |
3786 | | - | |
3787 | | - | |
| 3818 | + | |
| 3819 | + | |
| 3820 | + | |
3788 | 3821 | | |
3789 | 3822 | | |
3790 | 3823 | | |
3791 | 3824 | | |
3792 | | - | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
3793 | 3829 | | |
3794 | 3830 | | |
3795 | 3831 | | |
| |||
7219 | 7255 | | |
7220 | 7256 | | |
7221 | 7257 | | |
7222 | | - | |
7223 | | - | |
7224 | | - | |
7225 | | - | |
7226 | | - | |
7227 | | - | |
7228 | | - | |
| 7258 | + | |
| 7259 | + | |
| 7260 | + | |
| 7261 | + | |
| 7262 | + | |
| 7263 | + | |
| 7264 | + | |
| 7265 | + | |
| 7266 | + | |
7229 | 7267 | | |
| 7268 | + | |
| 7269 | + | |
7230 | 7270 | | |
7231 | 7271 | | |
7232 | 7272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67507 | 67507 | | |
67508 | 67508 | | |
67509 | 67509 | | |
| 67510 | + | |
67510 | 67511 | | |
67511 | 67512 | | |
67512 | 67513 | | |
| |||
67559 | 67560 | | |
67560 | 67561 | | |
67561 | 67562 | | |
| 67563 | + | |
| 67564 | + | |
| 67565 | + | |
67562 | 67566 | | |
67563 | 67567 | | |
67564 | 67568 | | |
| |||
67572 | 67576 | | |
67573 | 67577 | | |
67574 | 67578 | | |
| 67579 | + | |
| 67580 | + | |
| 67581 | + | |
| 67582 | + | |
67575 | 67583 | | |
67576 | | - | |
67577 | | - | |
| 67584 | + | |
| 67585 | + | |
67578 | 67586 | | |
67579 | 67587 | | |
67580 | 67588 | | |
| |||
67676 | 67684 | | |
67677 | 67685 | | |
67678 | 67686 | | |
| 67687 | + | |
67679 | 67688 | | |
67680 | 67689 | | |
67681 | 67690 | | |
| |||
67818 | 67827 | | |
67819 | 67828 | | |
67820 | 67829 | | |
| 67830 | + | |
| 67831 | + | |
| 67832 | + | |
| 67833 | + | |
| 67834 | + | |
| 67835 | + | |
67821 | 67836 | | |
67822 | 67837 | | |
67823 | 67838 | | |
| |||
67900 | 67915 | | |
67901 | 67916 | | |
67902 | 67917 | | |
| 67918 | + | |
67903 | 67919 | | |
67904 | 67920 | | |
67905 | 67921 | | |
| |||
68044 | 68060 | | |
68045 | 68061 | | |
68046 | 68062 | | |
68047 | | - | |
| 68063 | + | |
| 68064 | + | |
68048 | 68065 | | |
68049 | 68066 | | |
68050 | 68067 | | |
68051 | 68068 | | |
| 68069 | + | |
68052 | 68070 | | |
68053 | 68071 | | |
68054 | 68072 | | |
| |||
0 commit comments