9#include <winpr/stream.h>
10#include <winpr/wtypes.h>
12static UINT32 fuzz_var_uint_bytes(UINT8 cbLen)
25static UINT32 fuzz_read_variable_uint(
wStream* s, UINT8 cbLen)
32 value = Stream_Get_UINT8(s);
35 value = Stream_Get_UINT16(s);
38 value = Stream_Get_UINT32(s);
47 CREATE_REQUEST_PDU = 0x01,
48 DATA_FIRST_PDU = 0x02,
50 CLOSE_REQUEST_PDU = 0x04,
51 CAPABILITY_REQUEST_PDU = 0x05,
52 DATA_FIRST_COMPRESSED_PDU = 0x06,
53 DATA_COMPRESSED_PDU = 0x07
56static int fuzz_process_one_pdu(
wStream* s)
58 const size_t required = 1;
60 if (!Stream_CheckAndLogRequiredLength(
"fuzz", s, required))
63 UINT8 header = Stream_Get_UINT8(s);
64 UINT8 command = (header & 0xf0) >> 4;
65 UINT8 spacing = (header & 0x0c) >> 2;
66 UINT8 cbChId = (header & 0x03);
67 size_t needed = fuzz_var_uint_bytes(cbChId);
72 case DATA_FIRST_COMPRESSED_PDU:
73 if (!Stream_CheckAndLogRequiredLength(
"fuzz", s, needed + fuzz_var_uint_bytes(spacing)))
75 (void)fuzz_read_variable_uint(s, cbChId);
76 (void)fuzz_read_variable_uint(s, spacing);
79 case DATA_COMPRESSED_PDU:
80 case CLOSE_REQUEST_PDU:
81 case CREATE_REQUEST_PDU:
82 if (!Stream_CheckAndLogRequiredLength(
"fuzz", s, needed))
84 (void)fuzz_read_variable_uint(s, cbChId);
86 case CAPABILITY_REQUEST_PDU:
87 if (!Stream_CheckAndLogRequiredLength(
"fuzz", s, 2))
95 if (!Stream_CheckAndLogRequiredLength(
"fuzz", s, 2))
99 size_t bodyLen = Stream_Get_UINT16(s);
100 const size_t remaining = Stream_GetRemainingLength(s);
101 if (bodyLen > remaining)
103 Stream_Seek(s, bodyLen);
109int LLVMFuzzerTestOneInput(
const uint8_t* data,
size_t size)
111 if ((size == 0) || (size > (1u << 20)))
114 wStream* s = Stream_New((BYTE*)data, size);
118 for (
size_t index = 0; index < 64; index++)
120 if (Stream_GetRemainingLength(s) == 0)
122 if (fuzz_process_one_pdu(s) != 0)
126 Stream_Free(s, FALSE);