Coverage Report

Created: 2026-09-01 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/channels/cliprdr/client/test/TestFuzzChannelCliprdr.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * libFuzzer harness for cliprdr PDU parsing
4
 */
5
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/channels/cliprdr.h>
14
15
#include "../../cliprdr_common.h"
16
17
static wLog* g_Log = nullptr;
18
19
static UINT32 fuzz_stream_len_u32(wStream* s)
20
1.06k
{
21
1.06k
  const size_t remaining = Stream_GetRemainingLength(s);
22
1.06k
  return (remaining > UINT32_MAX) ? UINT32_MAX : (UINT32)remaining;
23
1.06k
}
24
25
static void fuzz_format_list(wStream* s, BOOL longNames)
26
528
{
27
528
  CLIPRDR_FORMAT_LIST list = WINPR_C_ARRAY_INIT;
28
528
  list.common.dataLen = fuzz_stream_len_u32(s);
29
30
528
  if (cliprdr_read_format_list(g_Log, s, &list, longNames) == CHANNEL_RC_OK)
31
314
    cliprdr_free_format_list(&list);
32
528
}
33
34
static void fuzz_format_data_request(wStream* s)
35
57
{
36
57
  CLIPRDR_FORMAT_DATA_REQUEST request = WINPR_C_ARRAY_INIT;
37
57
  request.common.dataLen = fuzz_stream_len_u32(s);
38
57
  (void)cliprdr_read_format_data_request(s, &request);
39
57
}
40
41
static void fuzz_format_data_response(wStream* s)
42
28
{
43
28
  CLIPRDR_FORMAT_DATA_RESPONSE response = WINPR_C_ARRAY_INIT;
44
28
  response.common.dataLen = fuzz_stream_len_u32(s);
45
28
  (void)cliprdr_read_format_data_response(s, &response);
46
28
}
47
48
static void fuzz_file_contents_request(wStream* s)
49
319
{
50
319
  CLIPRDR_FILE_CONTENTS_REQUEST request = WINPR_C_ARRAY_INIT;
51
319
  request.common.dataLen = fuzz_stream_len_u32(s);
52
319
  (void)cliprdr_read_file_contents_request(s, &request);
53
319
}
54
55
static void fuzz_file_contents_response(wStream* s)
56
64
{
57
64
  CLIPRDR_FILE_CONTENTS_RESPONSE response = WINPR_C_ARRAY_INIT;
58
64
  const UINT32 dataLen = fuzz_stream_len_u32(s);
59
60
64
  response.common.dataLen = (dataLen >= 4) ? dataLen : 4;
61
64
  (void)cliprdr_read_file_contents_response(s, &response);
62
64
}
63
64
static void fuzz_unlock(wStream* s)
65
65
{
66
65
  CLIPRDR_UNLOCK_CLIPBOARD_DATA data = WINPR_C_ARRAY_INIT;
67
65
  data.common.dataLen = fuzz_stream_len_u32(s);
68
65
  (void)cliprdr_read_unlock_clipdata(s, &data);
69
65
}
70
71
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72
1.06k
{
73
1.06k
  if (size < 2)
74
1
    return 0;
75
1.06k
  if (size > (1u << 20))
76
0
    return 0;
77
78
1.06k
  if (!g_Log)
79
1
    g_Log = WLog_Get("fuzz.cliprdr");
80
81
1.06k
  BOOL longNames = (data[1] & 0x1) != 0;
82
1.06k
  const uint8_t* body = data + 2;
83
84
1.06k
  wStream buffer = WINPR_C_ARRAY_INIT;
85
1.06k
  wStream* s = Stream_StaticConstInit(&buffer, body, size - 2);
86
1.06k
  if (!s)
87
0
    return 0;
88
89
1.06k
  switch (data[0] % 6)
90
1.06k
  {
91
528
    case 0:
92
528
      fuzz_format_list(s, longNames);
93
528
      break;
94
57
    case 1:
95
57
      fuzz_format_data_request(s);
96
57
      break;
97
28
    case 2:
98
28
      fuzz_format_data_response(s);
99
28
      break;
100
319
    case 3:
101
319
      fuzz_file_contents_request(s);
102
319
      break;
103
64
    case 4:
104
64
      fuzz_file_contents_response(s);
105
64
      break;
106
65
    case 5:
107
65
      fuzz_unlock(s);
108
65
      break;
109
0
    default:
110
0
      break;
111
1.06k
  }
112
113
1.06k
  return 0;
114
1.06k
}