Commit c3af983
committed
stream_buffer: reject required-space overflow at runtime in message send
Defect: xStreamBufferSend() and xStreamBufferSendFromISR() on a message buffer
can perform an out-of-bounds write when the required-space computation for a
message overflows size_t and configASSERT() is compiled out.
Root cause: for message buffers the code computes
xRequiredSpace = xDataLengthBytes + sbBYTES_TO_STORE_MESSAGE_LENGTH and guards
it only with configASSERT( xRequiredSpace > xDataLengthBytes ). When the
addition wraps size_t, the wrapped (smaller) xRequiredSpace passes the
subsequent space checks and the send proceeds to copy xDataLengthBytes bytes,
writing past the buffer. With asserts disabled there is no guard at all.
Fix: add a runtime check that returns 0 (nothing sent) when
xRequiredSpace <= xDataLengthBytes, in both the task and FromISR send paths, so
a wrapping message length is rejected regardless of the configASSERT() setting.
A host regression test kept outside this repository demonstrates the fault
before the change and its absence afterwards (red then green).1 parent a17db1c commit c3af983
1 file changed
Lines changed: 42 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
823 | | - | |
| 823 | + | |
| 824 | + | |
824 | 825 | | |
825 | 826 | | |
826 | 827 | | |
| 828 | + | |
827 | 829 | | |
828 | 830 | | |
829 | 831 | | |
| |||
845 | 847 | | |
846 | 848 | | |
847 | 849 | | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
848 | 862 | | |
849 | 863 | | |
850 | | - | |
| 864 | + | |
851 | 865 | | |
852 | 866 | | |
853 | 867 | | |
| |||
921 | 935 | | |
922 | 936 | | |
923 | 937 | | |
924 | | - | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
925 | 942 | | |
926 | 943 | | |
927 | 944 | | |
| |||
955 | 972 | | |
956 | 973 | | |
957 | 974 | | |
958 | | - | |
| 975 | + | |
| 976 | + | |
959 | 977 | | |
| 978 | + | |
960 | 979 | | |
961 | 980 | | |
962 | 981 | | |
| |||
973 | 992 | | |
974 | 993 | | |
975 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
976 | 1009 | | |
977 | 1010 | | |
978 | 1011 | | |
979 | 1012 | | |
980 | 1013 | | |
981 | 1014 | | |
982 | | - | |
983 | | - | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
984 | 1020 | | |
985 | 1021 | | |
986 | 1022 | | |
| |||
0 commit comments