Commit 8492b0f
authored
Merge commit from fork
* tport/ws: Fix heap OOB write in WebSocket payload unmasking.
The XOR unmask loop iterated `wsh->datalen` (bytes in `wsh->buffer`:
header + payload tail) but indexed into `wsh->body`, which holds only
the per-frame payload bytes in `wsh->bbuffer`. The loop wrote up to
14 XOR'd bytes past the live payload region of `bbuffer`.
Bound the loop by `wsh->rplen` (payload bytes copied into body), which
is the correct cross-buffer count.
* tport/ws: Fix heap OOB writes from undersized WebSocket buffers
`ws_read_frame()` and the handshake parser undersized the heap buffers
two ways, each writing past the allocation.
1. Trailing NUL. `ws_init()` and the `bbuffer` realloc sized buffers at
exactly `buflen` / `bbuflen`, but a terminating '\0' is written at
`buffer[datalen]` / `body[rplen]`. A buffer filled to capacity put
that NUL one byte past the chunk. Fix: reserve a NUL slot, allocating
`buflen + 1` / `bbuflen + 1` at init and on realloc.
2. Body undersized on the fragmentation path. The `bbuffer` grow check
sized on the bytes still to read, not the full frame payload. Payload
bytes arriving with the header in the initial read are copied in
separately, so the body holds the whole `plen` at offset `blen`; the
buffer was under-allocated by those bytes, letting a fragmented
message write past the allocation. Fix: size on `blen + plen` (prior
fragments plus this frame's full payload).1 parent a404c31 commit 8492b0f
2 files changed
Lines changed: 15 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
743 | | - | |
744 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
745 | 746 | | |
746 | 747 | | |
747 | 748 | | |
| |||
1043 | 1044 | | |
1044 | 1045 | | |
1045 | 1046 | | |
1046 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
1047 | 1050 | | |
1048 | 1051 | | |
1049 | | - | |
| 1052 | + | |
1050 | 1053 | | |
1051 | 1054 | | |
1052 | 1055 | | |
1053 | 1056 | | |
1054 | 1057 | | |
1055 | 1058 | | |
1056 | 1059 | | |
1057 | | - | |
| 1060 | + | |
| 1061 | + | |
1058 | 1062 | | |
1059 | 1063 | | |
1060 | 1064 | | |
| |||
1086 | 1090 | | |
1087 | 1091 | | |
1088 | 1092 | | |
1089 | | - | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1090 | 1096 | | |
1091 | 1097 | | |
1092 | 1098 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
0 commit comments