Repository navigation
Commit 67866d7
authored
Merge commit from fork
`ws_read_frame()` sizes `wsh->bbuffer` from the length declared in each
frame header, so that length needs a bound that holds for every library
consumer and across the fragments of one message. The receive adapter
then has to hand the message to the parser with the length it actually
transferred, which is what lets the SIP layer decide the outcome for an
oversized message rather than the transport deciding for it.
`libsofia-sip-ua/tport/ws.c`:
- `ws_global_payload_size_max` defaults to `WS_PAYLOAD_SIZE_MAX_DEFAULT`
(4 MiB) instead of `0`, so the cap applies without a call to
`ws_set_global_payload_size_max()`. The cap bounds what one message can
make this layer allocate, not what size a message may be: keeping it
above NTA's 2 MiB `sa_maxsize` leaves the size limit with the SIP layer,
which can answer 413, and reserves the cap for cutting off anything
beyond that.
- `ws_set_global_payload_size_max()` maps a non-positive argument to the
default. Once the check below runs unconditionally there is no value
left that means unlimited: `0` would reject every non-empty frame. A
caller passing `0` to mean unlimited gets the default instead.
- The 64-bit length form is bounded against the cap while still
`uint64_t`, then narrowed. Passing that test makes the assignment to
`wsh->plen` exact even where `ssize_t` is 32 bits, and it enforces the
RFC 6455 5.2 rule that the top bit of that form be 0.
- The accumulated length is checked once the frame header is decoded, on
every frame, rather than inside the branch that grows `wsh->bbuffer`.
The decision no longer depends on `blen + wsh->plen`, the sum it is
there to bound, and comparing against the cap by subtraction keeps that
sum in range for the sizing arithmetic that follows.
- `blen` becomes `ssize_t`, matching the `wsh->body - wsh->bbuffer`
difference it holds.
`libsofia-sip-ua/tport/tport_type_ws.c`:
- `tport_recv_stream_ws()` commits the number of bytes it copied into the
message rather than the number the frame held. The two differ when the
message exceeds `sa_maxsize`: `tport_recv_iovec()` then provisions a
short buffer so the parser still receives a prefix. The assertion after
the copy loop is relaxed to match, and the message reaches the parser
flagged `MSG_FLG_TOOLARGE`, which the transaction layer answers with
413.1 parent 8492b0f commit 67866d7
2 files changed
Lines changed: 46 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
249 | 251 | | |
250 | | - | |
| 252 | + | |
251 | 253 | | |
252 | 254 | | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
256 | | - | |
257 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | | - | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
713 | 719 | | |
714 | 720 | | |
715 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
716 | 727 | | |
717 | 728 | | |
718 | | - | |
| 729 | + | |
719 | 730 | | |
720 | 731 | | |
721 | 732 | | |
| |||
911 | 922 | | |
912 | 923 | | |
913 | 924 | | |
914 | | - | |
| 925 | + | |
915 | 926 | | |
916 | 927 | | |
917 | 928 | | |
| |||
994 | 1005 | | |
995 | 1006 | | |
996 | 1007 | | |
997 | | - | |
| 1008 | + | |
998 | 1009 | | |
999 | 1010 | | |
1000 | 1011 | | |
| |||
1007 | 1018 | | |
1008 | 1019 | | |
1009 | 1020 | | |
1010 | | - | |
| 1021 | + | |
1011 | 1022 | | |
1012 | | - | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1013 | 1034 | | |
1014 | 1035 | | |
1015 | 1036 | | |
| |||
1034 | 1055 | | |
1035 | 1056 | | |
1036 | 1057 | | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1037 | 1068 | | |
1038 | 1069 | | |
1039 | 1070 | | |
| |||
1042 | 1073 | | |
1043 | 1074 | | |
1044 | 1075 | | |
1045 | | - | |
1046 | | - | |
1047 | 1076 | | |
1048 | | - | |
| 1077 | + | |
1049 | 1078 | | |
1050 | 1079 | | |
1051 | 1080 | | |
1052 | 1081 | | |
1053 | 1082 | | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | 1083 | | |
1061 | 1084 | | |
1062 | 1085 | | |
| |||
0 commit comments