Coverage Report

Created: 2026-07-28 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uWebSockets/fuzzing/WebSocket.cpp
Line
Count
Source
1
/* This is a fuzz test of the websocket parser */
2
3
#define WIN32_EXPORT
4
5
#include "helpers.h"
6
7
/* We test the websocket parser */
8
#include "../src/WebSocketProtocol.h"
9
10
struct Impl {
11
81.0k
    static bool refusePayloadLength(uint64_t length, uWS::WebSocketState<true> *wState, void *s) {
12
13
        /* We need a limit */
14
81.0k
        if (length > 16000) {
15
694
            return true;
16
694
        }
17
18
        /* Return ok */
19
80.3k
        return false;
20
81.0k
    }
21
22
34.0k
    static bool setCompressed(uWS::WebSocketState<true> *wState, void *s) {
23
        /* We support it */
24
34.0k
        return true;
25
34.0k
    }
26
27
173k
    static void forceClose(uWS::WebSocketState<true> *wState, void *s, std::string_view reason = {}) {
28
29
173k
    }
30
31
109k
    static bool handleFragment(char *data, size_t length, unsigned int remainingBytes, int opCode, bool fin, uWS::WebSocketState<true> *webSocketState, void *s) {
32
33
109k
        if (opCode == uWS::TEXT) {
34
34.3k
            if (!uWS::protocol::isValidUtf8((unsigned char *)data, length)) {
35
                /* Return break */
36
18.2k
                return true;
37
18.2k
            }
38
74.6k
        } else if (opCode == uWS::CLOSE) {
39
54.0k
            uWS::protocol::parseClosePayload((char *)data, length);
40
54.0k
        }
41
42
        /* Return ok */
43
90.7k
        return false;
44
109k
    }
45
};
46
47
8.15k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
48
49
    /* Create the parser state */
50
8.15k
    uWS::WebSocketState<true> state;
51
52
210k
    makeChunked(makePadded(data, size), size, [&state](const uint8_t *data, size_t size) {
53
        /* Parse it */
54
210k
        uWS::WebSocketProtocol<true, Impl>::consume((char *) data, size, &state, nullptr);
55
210k
    });
56
57
8.15k
    return 0;
58
8.15k
}
59