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#include <freerdp/freerdp.h>
15
16#include "../rail_main.h"
17#include "../rail_orders.h"
18
19static void dealloc(railPlugin* plugin)
20{
21 if (!plugin)
22 return;
23 freerdp_settings_free(plugin->rdpcontext->settings);
24 free(plugin->rdpcontext);
25 free(plugin);
26}
27
28WINPR_ATTR_MALLOC(dealloc, 1)
29static railPlugin* alloc(void)
30{
31 railPlugin* rail = (railPlugin*)calloc(1, sizeof(railPlugin));
32 if (!rail)
33 return nullptr;
34 rail->rdpcontext = calloc(1, sizeof(rdpContext));
35 if (!rail->rdpcontext)
36 goto fail;
37
38 rail->rdpcontext->settings = freerdp_settings_new(0);
39 if (!rail->rdpcontext->settings)
40 goto fail;
41 return rail;
42fail:
43 dealloc(rail);
44 return nullptr;
45}
46
47int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
48{
49 if (size < 2)
50 return 0;
51 if (size > (1u << 20))
52 return 0;
53
54 int rc = -1;
55
56 wLog* root = WLog_GetRoot();
57 (void)WLog_SetLogLevel(root, WLOG_TRACE);
58 (void)WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);
59
60 railPlugin* g_rail = alloc();
61 RailClientContext* context = (RailClientContext*)calloc(1, sizeof(RailClientContext));
62 wStream* s = Stream_New(nullptr, size);
63 if (!g_rail || !context || !s)
64 goto fail;
65
66 g_rail->log = WLog_Get("fuzz.rail");
67
68 /* A context is required (handlers bail on nullptr); nullptr callbacks skip dispatch. */
69
70 g_rail->context = context;
71 g_rail->channelEntryPoints.pInterface = context;
72
73 /* rail_order_recv owns and frees the stream (Stream_Free(s, TRUE)); give it an owned copy. */
74
75 Stream_Write(s, data, size);
76 Stream_SealLength(s);
77 if (!Stream_SetPosition(s, 0))
78 goto fail;
79
80 (void)rail_order_recv(g_rail, s);
81 s = nullptr; // Freed up by rail_order_recv
82
83 rc = 0;
84
85fail:
86 Stream_Free(s, TRUE);
87 free(context);
88 dealloc(g_rail);
89 return rc;
90}
FREERDP_API rdpSettings * freerdp_settings_new(DWORD flags)
creates a new setting struct
FREERDP_API void freerdp_settings_free(rdpSettings *settings)
Free a settings struct with all data in it.