Commit e2b6581
committed
stream_buffer: reject message length truncation at runtime in writer
Defect: prvWriteMessageToBuffer() can write a truncated message-length header
into a message buffer when the data length does not fit the configured
configMESSAGE_BUFFER_LENGTH_TYPE and configASSERT() is compiled out,
desynchronizing framing at the receiver.
Root cause: the writer stores the length as a configMESSAGE_BUFFER_LENGTH_TYPE
value xMessageLength and only guards the "fits without truncation" condition
with configASSERT( ( size_t ) xMessageLength == xDataLengthBytes ). The
subsequent write was gated solely on available space, so with asserts disabled
a length that overflows the length type is written truncated while the full
data is copied, corrupting the message framing seen by the receiver.
Fix: gate the length-plus-data write on
( ( size_t ) xMessageLength == xDataLengthBytes ) in addition to the space
check. When the length cannot be represented without truncation, take the
"not enough space" path and write nothing. This runtime check is the only guard
against truncation when asserts are disabled.
A host regression test kept outside this repository demonstrates the fault
before the change and its absence afterwards (red then green).1 parent bc05723 commit e2b6581
1 file changed
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1065 | 1065 | | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | | - | |
| 1068 | + | |
1069 | 1069 | | |
1070 | | - | |
| 1070 | + | |
| 1071 | + | |
1071 | 1072 | | |
1072 | 1073 | | |
1073 | 1074 | | |
1074 | 1075 | | |
1075 | 1076 | | |
1076 | 1077 | | |
1077 | | - | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1078 | 1083 | | |
1079 | 1084 | | |
1080 | 1085 | | |
| |||
0 commit comments