Commit 81c11c9
committed
Fix NO_PKCS7_STREAM infinite loop on constructed-definite EnvelopedData
The fragmented-OCTET-STRING loop in wc_PKCS7_DecodeEnvelopedData() only
breaks on error under !NO_PKCS7_STREAM; the non-streaming build has no
error exit and relies solely on finding an indefinite EOC (00 00). A
constructed definite-length [0] whose inner OCTET STRING(s) are consumed
without an EOC terminator (e.g. a definite [0] wrapping multiple OCTET
STRINGs, or a single OCTET STRING followed by trailing bytes) leaves the
scan running past the end of the buffer: GetASNTag keeps failing, ret is
set but the loop never breaks, idx stops advancing, and it spins forever
-- a hang / denial of service on a NO_PKCS7_STREAM decoder fed a
malformed message.
Add the equivalent non-streaming error exit: after the EOC check (so a
valid indefinite message still terminates on its EOC first) break when
ret is non-zero. Streaming behavior is unchanged -- the break is guarded
by #ifdef NO_PKCS7_STREAM.
Exposed by test_wc_PKCS7_DecodeEnvelopedData_constructedDefiniteOctet:
its negative cases decode exactly these malformed shapes and hung the
NO_PKCS7_STREAM CI configs (make check timed out and was cancelled) until
this fix. The single definite-length OCTET STRING form that the decoder
now unwraps to the primitive path was already handled and is unaffected.1 parent c82cddb commit 81c11c9
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14752 | 14752 | | |
14753 | 14753 | | |
14754 | 14754 | | |
| 14755 | + | |
| 14756 | + | |
| 14757 | + | |
| 14758 | + | |
| 14759 | + | |
| 14760 | + | |
| 14761 | + | |
| 14762 | + | |
| 14763 | + | |
| 14764 | + | |
| 14765 | + | |
| 14766 | + | |
14755 | 14767 | | |
14756 | 14768 | | |
14757 | 14769 | | |
| |||
0 commit comments