Coverage Report

Created: 2026-04-12 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/channels/rdpgfx/rdpgfx_common.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * Graphics Pipeline Extension
4
 *
5
 * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 * Copyright 2015 Thincast Technologies GmbH
7
 * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *     http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21
22
#include <freerdp/config.h>
23
24
#include <winpr/crt.h>
25
#include <winpr/assert.h>
26
#include <winpr/stream.h>
27
28
#include "rdpgfx_common.h"
29
30
/**
31
 * Function description
32
 *
33
 * @return 0 on success, otherwise a Win32 error code
34
 */
35
UINT rdpgfx_read_header(wLog* log, wStream* s, RDPGFX_HEADER* header)
36
0
{
37
0
  WINPR_ASSERT(s);
38
0
  WINPR_ASSERT(header);
39
40
0
  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
41
0
    return CHANNEL_RC_NO_MEMORY;
42
43
0
  Stream_Read_UINT16(s, header->cmdId);     /* cmdId (2 bytes) */
44
0
  Stream_Read_UINT16(s, header->flags);     /* flags (2 bytes) */
45
0
  Stream_Read_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
46
47
0
  if (header->pduLength < 8)
48
0
  {
49
0
    WLog_Print(log, WLOG_ERROR, "header->pduLength %u less than 8!", header->pduLength);
50
0
    return ERROR_INVALID_DATA;
51
0
  }
52
0
  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, (header->pduLength - 8)))
53
0
    return ERROR_INVALID_DATA;
54
55
0
  return CHANNEL_RC_OK;
56
0
}
57
58
/**
59
 * Function description
60
 *
61
 * @return 0 on success, otherwise a Win32 error code
62
 */
63
UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header)
64
0
{
65
0
  WINPR_ASSERT(s);
66
0
  WINPR_ASSERT(header);
67
68
0
  if (!Stream_EnsureRemainingCapacity(s, 8))
69
0
    return CHANNEL_RC_NO_MEMORY;
70
0
  Stream_Write_UINT16(s, header->cmdId);     /* cmdId (2 bytes) */
71
0
  Stream_Write_UINT16(s, header->flags);     /* flags (2 bytes) */
72
0
  Stream_Write_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
73
0
  return CHANNEL_RC_OK;
74
0
}
75
76
/**
77
 * Function description
78
 *
79
 * @return 0 on success, otherwise a Win32 error code
80
 */
81
UINT rdpgfx_read_point16(wLog* log, wStream* s, RDPGFX_POINT16* pt16)
82
0
{
83
0
  WINPR_ASSERT(s);
84
0
  WINPR_ASSERT(pt16);
85
86
0
  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
87
0
    return ERROR_INVALID_DATA;
88
89
0
  Stream_Read_UINT16(s, pt16->x); /* x (2 bytes) */
90
0
  Stream_Read_UINT16(s, pt16->y); /* y (2 bytes) */
91
0
  return CHANNEL_RC_OK;
92
0
}
93
94
/**
95
 * Function description
96
 *
97
 * @return 0 on success, otherwise a Win32 error code
98
 */
99
UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16)
100
0
{
101
0
  WINPR_ASSERT(s);
102
0
  WINPR_ASSERT(point16);
103
104
0
  if (!Stream_EnsureRemainingCapacity(s, 4))
105
0
    return CHANNEL_RC_NO_MEMORY;
106
107
0
  Stream_Write_UINT16(s, point16->x); /* x (2 bytes) */
108
0
  Stream_Write_UINT16(s, point16->y); /* y (2 bytes) */
109
0
  return CHANNEL_RC_OK;
110
0
}
111
112
/**
113
 * Function description
114
 *
115
 * @return 0 on success, otherwise a Win32 error code
116
 */
117
UINT rdpgfx_read_rect16(wLog* log, wStream* s, RECTANGLE_16* rect16)
118
0
{
119
0
  WINPR_ASSERT(s);
120
0
  WINPR_ASSERT(rect16);
121
122
0
  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8))
123
0
    return ERROR_INVALID_DATA;
124
125
0
  Stream_Read_UINT16(s, rect16->left);   /* left (2 bytes) */
126
0
  Stream_Read_UINT16(s, rect16->top);    /* top (2 bytes) */
127
0
  Stream_Read_UINT16(s, rect16->right);  /* right (2 bytes) */
128
0
  Stream_Read_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
129
0
  if (rect16->left >= rect16->right)
130
0
    return ERROR_INVALID_DATA;
131
0
  if (rect16->top >= rect16->bottom)
132
0
    return ERROR_INVALID_DATA;
133
0
  return CHANNEL_RC_OK;
134
0
}
135
136
/**
137
 * Function description
138
 *
139
 * @return 0 on success, otherwise a Win32 error code
140
 */
141
UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16)
142
0
{
143
0
  WINPR_ASSERT(s);
144
0
  WINPR_ASSERT(rect16);
145
146
0
  if (!Stream_EnsureRemainingCapacity(s, 8))
147
0
    return CHANNEL_RC_NO_MEMORY;
148
149
0
  Stream_Write_UINT16(s, rect16->left);   /* left (2 bytes) */
150
0
  Stream_Write_UINT16(s, rect16->top);    /* top (2 bytes) */
151
0
  Stream_Write_UINT16(s, rect16->right);  /* right (2 bytes) */
152
0
  Stream_Write_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
153
0
  return CHANNEL_RC_OK;
154
0
}
155
156
/**
157
 * Function description
158
 *
159
 * @return 0 on success, otherwise a Win32 error code
160
 */
161
UINT rdpgfx_read_color32(wLog* log, wStream* s, RDPGFX_COLOR32* color32)
162
0
{
163
0
  WINPR_ASSERT(s);
164
0
  WINPR_ASSERT(color32);
165
166
0
  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4))
167
0
    return ERROR_INVALID_DATA;
168
169
0
  Stream_Read_UINT8(s, color32->B);  /* B (1 byte) */
170
0
  Stream_Read_UINT8(s, color32->G);  /* G (1 byte) */
171
0
  Stream_Read_UINT8(s, color32->R);  /* R (1 byte) */
172
0
  Stream_Read_UINT8(s, color32->XA); /* XA (1 byte) */
173
0
  return CHANNEL_RC_OK;
174
0
}
175
176
/**
177
 * Function description
178
 *
179
 * @return 0 on success, otherwise a Win32 error code
180
 */
181
UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32)
182
0
{
183
0
  WINPR_ASSERT(s);
184
0
  WINPR_ASSERT(color32);
185
186
0
  if (!Stream_EnsureRemainingCapacity(s, 4))
187
0
    return CHANNEL_RC_NO_MEMORY;
188
189
0
  Stream_Write_UINT8(s, color32->B);  /* B (1 byte) */
190
0
  Stream_Write_UINT8(s, color32->G);  /* G (1 byte) */
191
0
  Stream_Write_UINT8(s, color32->R);  /* R (1 byte) */
192
0
  Stream_Write_UINT8(s, color32->XA); /* XA (1 byte) */
193
0
  return CHANNEL_RC_OK;
194
0
}