]> git.ipfire.org Git - thirdparty/curl.git/commit
ws: tests and fixes
authorRuocco, Calvin <calvin.ruocco@vector.com>
Mon, 14 Apr 2025 15:59:45 +0000 (17:59 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 2 Jun 2025 09:15:38 +0000 (11:15 +0200)
commitd3594be6531df3d5eafcdd09f84ad9dee1777028
treec8078126949b3791f83a97cd46476e5bab161fcc
parent04c3895ceb2dbf9e62850080a658f9f26ad2293e
ws: tests and fixes

This started out as regression tests for the `curl_ws_recv()` and
`curl_ws_send()` implementation and ended up with a bugfix, additional
protocol validation and minor logging improvements.

- Fix reset of fragmented message decoder state when a PING/PONG is
  received in between message fragments.

- Fix undefined behavior (applying zero offset to null pointer) in
  curl_ws_send() when the given buffer is NULL.

- Detect invalid overlong PING/PONG/CLOSE frames.
- Detect invalid fragmented PING/PONG/CLOSE frames.
- Detect invalid sequences of fragmented frames.

  - a) A continuation frame (0x80...) is received without any ongoing
    fragmented message.
  - b) A new fragmented message is started (0x81/0x01/0x82/0x02...)
    before the ongoing fragmented message has terminated.

- Made logs for invalid opcodes easier to understand.
- Moved noisy logs to the `CURL_TRC_WS` log level.
- Unified the prefixes for WebSocket log messages: `[WS] ...`

- Add env var `CURL_WS_FORCE_ZERO_MASK` in debug builds.

  - If set, it forces the bit mask applied to outgoing payloads to
    0x00000000, which effectively means the payload is not masked at
    all. This drastically simplifies defining the expected `<protocol>`
    data in test cases.

- 2700: Frame types
- 2701: Invalid opcode 0x3
- 2702: Invalid opcode 0xB
- 2703: Invalid reserved bit RSV1 _(replaces 2310)_
- 2704: Invalid reserved bit RSV2
- 2705: Invalid reserved bit RSV3
- 2706: Invalid masked server message
- 2707: Peculiar frame sizes _(part. replaces 2311)_
- 2708: Automatic PONG
- 2709: No automatic PONG _(replaces 2312)_
- 2710: Unsolicited PONG
- 2711: Empty PING/PONG/CLOSE
- 2712: Max sized PING/PONG/CLOSE
- 2713: Invalid oversized PING _(replaces 2307)_
- 2714: Invalid oversized PONG
- 2715: Invalid oversized CLOSE
- 2716: Invalid fragmented PING
- 2717: Invalid fragmented PONG
- 2718: Invalid fragmented CLOSE
- 2719: Fragmented messages _(part. replaces 2311)_
- 2720: Fragmented messages with empty fragments
- 2721: Fragmented messages with interleaved pong
- 2722: Invalid fragmented message without initial frame
- 2723: Invalid fragmented message without final frame

- 2305: curl_ws_recv() loop reading three larger frames
  - This test involuntarily sent an invalid sequence of opcodes (0x01...,0x01...,0x81...) , but neither libcurl nor the test caught this! The correct sequence was tested in 2311 (0x01...,0x00...,0x80...). See below for 2311.
  - Validation of the opcode sequence was added to libcurl and is now tested in 2723.
  - Superseded by 2719 (fragmented message) and 2707 (large frames).
- 2307: overlong PING payload
  - The tested PING payload length check was actually missing, but the test didn't catch this since it involuntarily sent an invalid opcode (0x19... instead of 0x89...) so that the expected error occurred, but for the wrong reason.
  - Superseded by 2713.
- 2310: unknown reserved bit set in frame header
  - Superseded by 2703 and extended by 2704 and 2705.
- 2311: curl_ws_recv() read fragmented message
  - Superseded by 2719 (fragmented message) and 2707 (large frames).
- 2312: WebSockets no auto ping
  - Superseded by 2709.

- No tests for `CURLOPT_WRITEFUNCTION`.
- No tests for sending of invalid frames/fragments.

Closes #17136
41 files changed:
.mailmap
docs/libcurl/libcurl-env-dbg.md
lib/ws.c
tests/data/Makefile.am
tests/data/test2304
tests/data/test2305 [deleted file]
tests/data/test2307 [deleted file]
tests/data/test2310 [deleted file]
tests/data/test2311 [deleted file]
tests/data/test2312 [deleted file]
tests/data/test2700 [new file with mode: 0644]
tests/data/test2701 [new file with mode: 0644]
tests/data/test2702 [new file with mode: 0644]
tests/data/test2703 [new file with mode: 0644]
tests/data/test2704 [new file with mode: 0644]
tests/data/test2705 [new file with mode: 0644]
tests/data/test2706 [new file with mode: 0644]
tests/data/test2707 [new file with mode: 0644]
tests/data/test2708 [new file with mode: 0644]
tests/data/test2709 [new file with mode: 0644]
tests/data/test2710 [new file with mode: 0644]
tests/data/test2711 [new file with mode: 0644]
tests/data/test2712 [new file with mode: 0644]
tests/data/test2713 [new file with mode: 0644]
tests/data/test2714 [new file with mode: 0644]
tests/data/test2715 [new file with mode: 0644]
tests/data/test2716 [new file with mode: 0644]
tests/data/test2717 [new file with mode: 0644]
tests/data/test2718 [new file with mode: 0644]
tests/data/test2719 [new file with mode: 0644]
tests/data/test2720 [new file with mode: 0644]
tests/data/test2721 [new file with mode: 0644]
tests/data/test2722 [new file with mode: 0644]
tests/data/test2723 [new file with mode: 0644]
tests/http/test_20_websockets.py
tests/libtest/Makefile.inc
tests/libtest/lib2305.c [deleted file]
tests/libtest/lib2310.c [deleted file]
tests/libtest/lib2311.c [deleted file]
tests/libtest/lib2312.c [deleted file]
tests/libtest/lib2700.c [new file with mode: 0644]