FreeRDP
Loading...
Searching...
No Matches
TestFuzzChannelRail.c
1
6#include <stddef.h>
7#include <stdint.h>
8
9#include <winpr/crt.h>
10#include <winpr/stream.h>
11#include <winpr/wlog.h>
12
13#include <freerdp/client/rail.h>
14
15#include "../rail_main.h"
16#include "../rail_orders.h"
17
18static railPlugin* g_rail = nullptr;
19
20int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
21{
22 if (size < 2)
23 return 0;
24 if (size > (1u << 20))
25 return 0;
26
27 if (!g_rail)
28 {
29 g_rail = (railPlugin*)calloc(1, sizeof(railPlugin));
30 if (!g_rail)
31 return 0;
32
33 g_rail->log = WLog_Get("fuzz.rail");
34
35 /* A context is required (handlers bail on NULL); NULL callbacks skip dispatch. */
36 RailClientContext* context = (RailClientContext*)calloc(1, sizeof(RailClientContext));
37 g_rail->context = context;
38 g_rail->channelEntryPoints.pInterface = context;
39 }
40
41 /* rail_order_recv owns and frees the stream (Stream_Free(s, TRUE)); give it an owned copy. */
42 wStream* s = Stream_New(NULL, size);
43 if (!s)
44 return 0;
45
46 Stream_Write(s, data, size);
47 Stream_SealLength(s);
48 Stream_SetPosition(s, 0);
49
50 (void)rail_order_recv(g_rail, s);
51
52 return 0;
53}