Line data Source code
1 : /* this is a file autogenerated by spice_codegen.py */
2 : /*
3 : Copyright (C) 2013 Red Hat, Inc.
4 :
5 : This library is free software; you can redistribute it and/or
6 : modify it under the terms of the GNU Lesser General Public
7 : License as published by the Free Software Foundation; either
8 : version 2.1 of the License, or (at your option) any later version.
9 :
10 : This library is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : Lesser General Public License for more details.
14 :
15 : You should have received a copy of the GNU Lesser General Public
16 : License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 : */
18 :
19 : #include <config.h>
20 : #include "test-marshallers.h"
21 : #include <string.h>
22 : #include <assert.h>
23 : #include <stdlib.h>
24 : #include <stdio.h>
25 : #include <spice/protocol.h>
26 : #include <spice/macros.h>
27 : #include <common/mem.h>
28 : #include <common/demarshallers.h>
29 :
30 : #ifdef _MSC_VER
31 : #pragma warning(disable:4101)
32 : #endif
33 :
34 :
35 :
36 : #include <spice/start-packed.h>
37 : typedef struct SPICE_ATTR_PACKED {
38 : int16_t v;
39 : } int16_unaligned_t;
40 : typedef struct SPICE_ATTR_PACKED {
41 : uint16_t v;
42 : } uint16_unaligned_t;
43 : typedef struct SPICE_ATTR_PACKED {
44 : int32_t v;
45 : } int32_unaligned_t;
46 : typedef struct SPICE_ATTR_PACKED {
47 : uint32_t v;
48 : } uint32_unaligned_t;
49 : typedef struct SPICE_ATTR_PACKED {
50 : int64_t v;
51 : } int64_unaligned_t;
52 : typedef struct SPICE_ATTR_PACKED {
53 : uint64_t v;
54 : } uint64_unaligned_t;
55 : #include <spice/end-packed.h>
56 :
57 : #define read_int8(ptr) (*((int8_t *)(ptr)))
58 : #define write_int8(ptr, val) *(int8_t *)(ptr) = val
59 : #define read_uint8(ptr) (*((uint8_t *)(ptr)))
60 : #define write_uint8(ptr, val) *(uint8_t *)(ptr) = val
61 :
62 : #ifdef WORDS_BIGENDIAN
63 : #define read_int16(ptr) ((int16_t)SPICE_BYTESWAP16(((uint16_unaligned_t *)(ptr))->v))
64 : #define write_int16(ptr, val) ((uint16_unaligned_t *)(ptr))->v = SPICE_BYTESWAP16((uint16_t)val)
65 : #define read_uint16(ptr) ((uint16_t)SPICE_BYTESWAP16(((uint16_unaligned_t *)(ptr))->v))
66 : #define write_uint16(ptr, val) ((uint16_unaligned_t *)(ptr))->v = SPICE_BYTESWAP16((uint16_t)val)
67 : #define read_int32(ptr) ((int32_t)SPICE_BYTESWAP32(((uint32_unaligned_t *)(ptr))->v))
68 : #define write_int32(ptr, val) ((uint32_unaligned_t *)(ptr))->v = SPICE_BYTESWAP32((uint32_t)val)
69 : #define read_uint32(ptr) ((uint32_t)SPICE_BYTESWAP32(((uint32_unaligned_t *)(ptr))->v))
70 : #define write_uint32(ptr, val) ((uint32_unaligned_t *)(ptr))->v = SPICE_BYTESWAP32((uint32_t)val)
71 : #define read_int64(ptr) ((int64_t)SPICE_BYTESWAP64(((uint64_unaligned_t *)(ptr))->v))
72 : #define write_int64(ptr, val) ((uint64_unaligned_t *)(ptr))->v = SPICE_BYTESWAP64((uint64_t)val)
73 : #define read_uint64(ptr) ((uint64_t)SPICE_BYTESWAP64(((uint64_unaligned_t *)(ptr))->v))
74 : #define write_uint64(ptr, val) ((uint64_unaligned_t *)(ptr))->v = SPICE_BYTESWAP64((uint64_t)val)
75 : #else
76 : #define read_int16(ptr) (((int16_unaligned_t *)(ptr))->v)
77 : #define write_int16(ptr, val) (((int16_unaligned_t *)(ptr))->v) = val
78 : #define read_uint16(ptr) (((uint16_unaligned_t *)(ptr))->v)
79 : #define write_uint16(ptr, val) (((uint16_unaligned_t *)(ptr))->v) = val
80 : #define read_int32(ptr) (((int32_unaligned_t *)(ptr))->v)
81 : #define write_int32(ptr, val) (((int32_unaligned_t *)(ptr))->v) = val
82 : #define read_uint32(ptr) (((uint32_unaligned_t *)(ptr))->v)
83 : #define write_uint32(ptr, val) (((uint32_unaligned_t *)(ptr))->v) = val
84 : #define read_int64(ptr) (((int64_unaligned_t *)(ptr))->v)
85 : #define write_int64(ptr, val) (((int64_unaligned_t *)(ptr))->v) = val
86 : #define read_uint64(ptr) (((uint64_unaligned_t *)(ptr))->v)
87 : #define write_uint64(ptr, val) (((uint64_unaligned_t *)(ptr))->v) = val
88 : #endif
89 :
90 0 : static int8_t SPICE_GNUC_UNUSED consume_int8(uint8_t **ptr)
91 : {
92 : int8_t val;
93 0 : val = read_int8(*ptr);
94 0 : *ptr += 1;
95 0 : return val;
96 : }
97 :
98 2 : static uint8_t SPICE_GNUC_UNUSED consume_uint8(uint8_t **ptr)
99 : {
100 : uint8_t val;
101 2 : val = read_uint8(*ptr);
102 2 : *ptr += 1;
103 2 : return val;
104 : }
105 :
106 0 : static int16_t SPICE_GNUC_UNUSED consume_int16(uint8_t **ptr)
107 : {
108 : int16_t val;
109 0 : val = read_int16(*ptr);
110 0 : *ptr += 2;
111 0 : return val;
112 : }
113 :
114 1 : static uint16_t SPICE_GNUC_UNUSED consume_uint16(uint8_t **ptr)
115 : {
116 : uint16_t val;
117 1 : val = read_uint16(*ptr);
118 1 : *ptr += 2;
119 1 : return val;
120 : }
121 :
122 0 : static int32_t SPICE_GNUC_UNUSED consume_int32(uint8_t **ptr)
123 : {
124 : int32_t val;
125 0 : val = read_int32(*ptr);
126 0 : *ptr += 4;
127 0 : return val;
128 : }
129 :
130 5 : static uint32_t SPICE_GNUC_UNUSED consume_uint32(uint8_t **ptr)
131 : {
132 : uint32_t val;
133 5 : val = read_uint32(*ptr);
134 5 : *ptr += 4;
135 5 : return val;
136 : }
137 :
138 0 : static int64_t SPICE_GNUC_UNUSED consume_int64(uint8_t **ptr)
139 : {
140 : int64_t val;
141 0 : val = read_int64(*ptr);
142 0 : *ptr += 8;
143 0 : return val;
144 : }
145 :
146 2 : static uint64_t SPICE_GNUC_UNUSED consume_uint64(uint8_t **ptr)
147 : {
148 : uint64_t val;
149 2 : val = read_uint64(*ptr);
150 2 : *ptr += 8;
151 2 : return val;
152 : }
153 0 : static int SPICE_GNUC_UNUSED consume_fd(uint8_t **ptr SPICE_GNUC_UNUSED)
154 : {
155 0 : return -1;
156 : }
157 :
158 : typedef struct PointerInfo PointerInfo;
159 : typedef void (*message_destructor_t)(uint8_t *message);
160 : typedef uint8_t * (*parse_func_t)(uint8_t *message_start, uint8_t *message_end, uint8_t *struct_data, PointerInfo *ptr_info);
161 : typedef uint8_t * (*parse_msg_func_t)(uint8_t *message_start, uint8_t *message_end, size_t *size_out, message_destructor_t *free_message);
162 : typedef uint8_t * (*spice_parse_channel_func_t)(uint8_t *message_start, uint8_t *message_end, uint16_t message_type, int minor, size_t *size_out, message_destructor_t *free_message);
163 :
164 : struct PointerInfo {
165 : uint64_t offset;
166 : parse_func_t parse;
167 : void * *dest;
168 : uint64_t nelements;
169 : };
170 :
171 1 : static uint8_t * parse_array_uint64(uint8_t *message_start, SPICE_GNUC_UNUSED uint8_t *message_end, uint8_t *struct_data, PointerInfo *this_ptr_info)
172 : {
173 1 : uint8_t *in = message_start + this_ptr_info->offset;
174 : uint8_t *end;
175 : uint32_t i;
176 :
177 1 : end = struct_data;
178 3 : for (i = 0; i < this_ptr_info->nelements; i++) {
179 2 : *(uint64_t *)end = consume_uint64(&in);
180 2 : end += sizeof(uint64_t);
181 : }
182 1 : return end;
183 : }
184 :
185 1 : static uint8_t * parse_msg_main_ShortDataSubMarshall(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
186 : {
187 : SPICE_GNUC_UNUSED uint8_t *pos;
188 1 : uint8_t *start = message_start;
189 1 : uint8_t *data = NULL;
190 : uint64_t nw_size;
191 : uint64_t mem_size;
192 : uint8_t *in, *end;
193 : SPICE_GNUC_UNUSED intptr_t ptr_size;
194 1 : uint32_t n_ptr=0;
195 : PointerInfo ptr_info[1];
196 : uint64_t data__extra_size;
197 : uint64_t data__array__nelements;
198 : SpiceMsgMainShortDataSubMarshall *out;
199 : uint32_t i;
200 :
201 : { /* data */
202 : uint32_t data__value;
203 : uint64_t data__array__nw_size;
204 : uint64_t data__array__mem_size;
205 : uint32_t data_size__value;
206 1 : pos = (start + 5);
207 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
208 0 : goto error;
209 : }
210 1 : data__value = read_uint32(pos);
211 1 : if (SPICE_UNLIKELY(data__value >= (uintptr_t) (message_end - message_start))) {
212 0 : goto error;
213 : }
214 1 : pos = start + 1;
215 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
216 0 : goto error;
217 : }
218 1 : data_size__value = read_uint32(pos);
219 1 : data__array__nelements = data_size__value;
220 :
221 1 : data__array__nw_size = (8) * data__array__nelements;
222 1 : data__array__mem_size = sizeof(uint64_t) * data__array__nelements;
223 1 : if (SPICE_UNLIKELY(data__array__nw_size > (uintptr_t) (message_end - message_start - data__value))) {
224 0 : goto error;
225 : }
226 1 : data__extra_size = data__array__mem_size + /* for alignment */ 3;
227 : }
228 :
229 1 : nw_size = 9;
230 1 : mem_size = sizeof(SpiceMsgMainShortDataSubMarshall) + data__extra_size;
231 :
232 : /* Check if message fits in reported side */
233 1 : if (nw_size > (uintptr_t) (message_end - start)) {
234 0 : return NULL;
235 : }
236 :
237 : /* Validated extents and calculated size */
238 1 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
239 1 : if (SPICE_UNLIKELY(data == NULL)) {
240 0 : goto error;
241 : }
242 1 : end = data + sizeof(SpiceMsgMainShortDataSubMarshall);
243 1 : in = start;
244 :
245 1 : out = (SpiceMsgMainShortDataSubMarshall *)data;
246 :
247 1 : out->dummy_byte = consume_uint8(&in);
248 1 : out->data_size = consume_uint32(&in);
249 1 : ptr_info[n_ptr].offset = consume_uint32(&in);
250 1 : ptr_info[n_ptr].parse = parse_array_uint64;
251 1 : ptr_info[n_ptr].dest = (void **)&out->data;
252 1 : ptr_info[n_ptr].nelements = data__array__nelements;
253 1 : n_ptr++;
254 :
255 1 : assert(in <= message_end);
256 :
257 2 : for (i = 0; i < n_ptr; i++) {
258 1 : if (ptr_info[i].offset == 0) {
259 0 : *ptr_info[i].dest = NULL;
260 : } else {
261 : /* Align to 32 bit */
262 1 : end = (uint8_t *)SPICE_ALIGN((uintptr_t)end, 4);
263 1 : *ptr_info[i].dest = (void *)end;
264 1 : end = ptr_info[i].parse(message_start, message_end, end, &ptr_info[i]);
265 1 : if (SPICE_UNLIKELY(end == NULL)) {
266 0 : goto error;
267 : }
268 : }
269 : }
270 :
271 1 : assert(end <= data + mem_size);
272 :
273 1 : *size = end - data;
274 1 : *free_message = (message_destructor_t) free;
275 1 : return data;
276 :
277 0 : error:
278 0 : free(data);
279 0 : return NULL;
280 : }
281 :
282 0 : static uint8_t * parse_msg_main_ArrayMessage(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
283 : {
284 : SPICE_GNUC_UNUSED uint8_t *pos;
285 0 : uint8_t *start = message_start;
286 0 : uint8_t *data = NULL;
287 : uint64_t nw_size;
288 : uint64_t mem_size;
289 : uint8_t *in, *end;
290 : uint64_t name__nw_size, name__mem_size;
291 : uint64_t name__nelements;
292 : SpiceMsgMainArrayMessage *out;
293 :
294 : { /* name */
295 0 : if (SPICE_UNLIKELY((start + 0) > message_end)) {
296 0 : goto error;
297 : }
298 0 : name__nelements = message_end - (start + 0);
299 :
300 0 : name__nw_size = name__nelements;
301 0 : name__mem_size = sizeof(int8_t) * name__nelements;
302 : }
303 :
304 0 : nw_size = 0 + name__nw_size;
305 0 : mem_size = sizeof(SpiceMsgMainArrayMessage) + name__mem_size;
306 :
307 : /* Check if message fits in reported side */
308 0 : if (nw_size > (uintptr_t) (message_end - start)) {
309 0 : return NULL;
310 : }
311 :
312 : /* Validated extents and calculated size */
313 0 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
314 0 : if (SPICE_UNLIKELY(data == NULL)) {
315 0 : goto error;
316 : }
317 0 : end = data + sizeof(SpiceMsgMainArrayMessage);
318 0 : in = start;
319 :
320 0 : out = (SpiceMsgMainArrayMessage *)data;
321 :
322 : verify(sizeof(out->name) == 0);
323 0 : memcpy(out->name, in, name__nelements);
324 0 : in += name__nelements;
325 0 : end += name__nelements;
326 :
327 0 : assert(in <= message_end);
328 0 : assert(end <= data + mem_size);
329 :
330 0 : *size = end - data;
331 0 : *free_message = (message_destructor_t) free;
332 0 : return data;
333 :
334 0 : error:
335 0 : free(data);
336 0 : return NULL;
337 : }
338 :
339 1 : static uint8_t * parse_msg_main_Zeroes(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
340 : {
341 : SPICE_GNUC_UNUSED uint8_t *pos;
342 1 : uint8_t *start = message_start;
343 1 : uint8_t *data = NULL;
344 : uint64_t nw_size;
345 : uint64_t mem_size;
346 : uint8_t *in, *end;
347 : SpiceMsgMainZeroes *out;
348 :
349 1 : nw_size = 7;
350 1 : mem_size = sizeof(SpiceMsgMainZeroes);
351 :
352 : /* Check if message fits in reported side */
353 1 : if (nw_size > (uintptr_t) (message_end - start)) {
354 1 : return NULL;
355 : }
356 :
357 : /* Validated extents and calculated size */
358 0 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
359 0 : if (SPICE_UNLIKELY(data == NULL)) {
360 0 : goto error;
361 : }
362 0 : end = data + sizeof(SpiceMsgMainZeroes);
363 0 : in = start;
364 :
365 0 : out = (SpiceMsgMainZeroes *)data;
366 :
367 0 : consume_uint8(&in);
368 0 : out->n = consume_uint16(&in);
369 0 : consume_uint32(&in);
370 :
371 0 : assert(in <= message_end);
372 0 : assert(end <= data + mem_size);
373 :
374 0 : *size = end - data;
375 0 : *free_message = (message_destructor_t) free;
376 0 : return data;
377 :
378 0 : error:
379 0 : free(data);
380 0 : return NULL;
381 : }
382 :
383 1 : static uint8_t * parse_msg_main_channels_list(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
384 : {
385 : SPICE_GNUC_UNUSED uint8_t *pos;
386 1 : uint8_t *start = message_start;
387 1 : uint8_t *data = NULL;
388 : uint64_t nw_size;
389 : uint64_t mem_size;
390 : uint8_t *in, *end;
391 : uint64_t channels__nw_size, channels__mem_size;
392 : uint64_t channels__nelements;
393 : SpiceMsgChannels *out;
394 : uint32_t i;
395 :
396 : { /* channels */
397 : uint32_t num_of_channels__value;
398 1 : pos = start + 0;
399 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
400 0 : goto error;
401 : }
402 1 : num_of_channels__value = read_uint32(pos);
403 1 : channels__nelements = num_of_channels__value;
404 :
405 1 : channels__nw_size = (2) * channels__nelements;
406 1 : channels__mem_size = sizeof(uint16_t) * channels__nelements;
407 : }
408 :
409 1 : nw_size = 4 + channels__nw_size;
410 1 : mem_size = sizeof(SpiceMsgChannels) + channels__mem_size;
411 :
412 : /* Check if message fits in reported side */
413 1 : if (nw_size > (uintptr_t) (message_end - start)) {
414 1 : return NULL;
415 : }
416 :
417 : /* Validated extents and calculated size */
418 0 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
419 0 : if (SPICE_UNLIKELY(data == NULL)) {
420 0 : goto error;
421 : }
422 0 : end = data + sizeof(SpiceMsgChannels);
423 0 : in = start;
424 :
425 0 : out = (SpiceMsgChannels *)data;
426 :
427 0 : out->num_of_channels = consume_uint32(&in);
428 : verify(sizeof(out->channels) == 0);
429 0 : for (i = 0; i < channels__nelements; i++) {
430 0 : out->channels[i] = consume_uint16(&in);
431 0 : end += sizeof(uint16_t);
432 : }
433 :
434 0 : assert(in <= message_end);
435 0 : assert(end <= data + mem_size);
436 :
437 0 : *size = end - data;
438 0 : *free_message = (message_destructor_t) free;
439 0 : return data;
440 :
441 0 : error:
442 0 : free(data);
443 0 : return NULL;
444 : }
445 :
446 0 : static uint8_t * parse_msg_main_LenMessage(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
447 : {
448 : SPICE_GNUC_UNUSED uint8_t *pos;
449 0 : uint8_t *start = message_start;
450 0 : uint8_t *data = NULL;
451 : uint64_t nw_size;
452 : uint64_t mem_size;
453 : uint8_t *in, *end;
454 : uint64_t data__nw_size, data__mem_size;
455 : uint64_t data__nelements;
456 : SpiceMsgMainLenMessage *out;
457 : uint64_t dummy__nelements;
458 : uint32_t i;
459 :
460 : { /* data */
461 0 : if (SPICE_UNLIKELY((start + 8) > message_end)) {
462 0 : goto error;
463 : }
464 0 : data__nelements = message_end - (start + 8);
465 :
466 0 : data__nw_size = data__nelements;
467 0 : data__mem_size = sizeof(uint8_t) * data__nelements;
468 : }
469 :
470 0 : nw_size = 8 + data__nw_size;
471 0 : mem_size = sizeof(SpiceMsgMainLenMessage) + data__mem_size;
472 :
473 : /* Check if message fits in reported side */
474 0 : if (nw_size > (uintptr_t) (message_end - start)) {
475 0 : return NULL;
476 : }
477 :
478 : /* Validated extents and calculated size */
479 0 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
480 0 : if (SPICE_UNLIKELY(data == NULL)) {
481 0 : goto error;
482 : }
483 0 : end = data + sizeof(SpiceMsgMainLenMessage);
484 0 : in = start;
485 :
486 0 : out = (SpiceMsgMainLenMessage *)data;
487 :
488 0 : dummy__nelements = 2;
489 0 : for (i = 0; i < dummy__nelements; i++) {
490 0 : out->dummy[i] = consume_uint32(&in);
491 : }
492 : verify(sizeof(out->data) == 0);
493 0 : memcpy(out->data, in, data__nelements);
494 0 : in += data__nelements;
495 0 : end += data__nelements;
496 :
497 0 : assert(in <= message_end);
498 0 : assert(end <= data + mem_size);
499 :
500 0 : *size = end - data;
501 0 : *free_message = (message_destructor_t) free;
502 0 : return data;
503 :
504 0 : error:
505 0 : free(data);
506 0 : return NULL;
507 : }
508 :
509 2 : static uint8_t * parse_array_uint8_terminated(uint8_t *message_start, SPICE_GNUC_UNUSED uint8_t *message_end, uint8_t *struct_data, PointerInfo *this_ptr_info)
510 : {
511 2 : uint8_t *in = message_start + this_ptr_info->offset;
512 : uint8_t *end;
513 :
514 2 : end = struct_data;
515 2 : memcpy(end, in, this_ptr_info->nelements);
516 : #if defined(__GNUC__)
517 : #pragma GCC diagnostic push
518 : #pragma GCC diagnostic ignored "-Wstringop-overflow"
519 : #endif
520 2 : ((char *) (end))[this_ptr_info->nelements] = 0;
521 : #if defined(__GNUC__)
522 : #pragma GCC diagnostic pop
523 : #endif
524 2 : in += this_ptr_info->nelements;
525 2 : end += this_ptr_info->nelements;
526 2 : end += 1;
527 2 : return end;
528 : }
529 :
530 1 : static uint8_t * parse_msg_main_ZeroLen1(uint8_t *message_start, uint8_t *message_end, size_t *size, message_destructor_t *free_message)
531 : {
532 : SPICE_GNUC_UNUSED uint8_t *pos;
533 1 : uint8_t *start = message_start;
534 1 : uint8_t *data = NULL;
535 : uint64_t nw_size;
536 : uint64_t mem_size;
537 : uint8_t *in, *end;
538 : SPICE_GNUC_UNUSED intptr_t ptr_size;
539 1 : uint32_t n_ptr=0;
540 : PointerInfo ptr_info[2];
541 : uint64_t txt2__extra_size;
542 : uint64_t txt2__array__nelements;
543 : uint64_t txt3__nw_size, txt3__mem_size;
544 : uint64_t txt3__nelements;
545 1 : uint32_t txt3__saved_size = 0;
546 : uint64_t txt4__nw_size, txt4__mem_size;
547 : uint64_t txt4__nelements;
548 : SpiceMsgMainZeroLen1 *out;
549 : uint64_t txt1__nelements;
550 : uint64_t txt3__array__nelements;
551 : uint32_t i;
552 :
553 : { /* txt2 */
554 : uint32_t txt2__value;
555 : uint64_t txt2__array__nw_size;
556 : uint64_t txt2__array__mem_size;
557 : uint32_t txt2_len__value;
558 1 : pos = (start + 9);
559 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
560 0 : goto error;
561 : }
562 1 : txt2__value = read_uint32(pos);
563 1 : if (SPICE_UNLIKELY(txt2__value >= (uintptr_t) (message_end - message_start))) {
564 0 : goto error;
565 : }
566 1 : pos = start + 5;
567 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
568 0 : goto error;
569 : }
570 1 : txt2_len__value = read_uint32(pos);
571 1 : txt2__array__nelements = txt2_len__value;
572 :
573 1 : txt2__array__nw_size = txt2__array__nelements;
574 1 : txt2__array__mem_size = sizeof(uint8_t) * txt2__array__nelements + sizeof(uint8_t);
575 1 : txt2__array__mem_size = SPICE_ALIGN(txt2__array__mem_size, 4);
576 1 : if (SPICE_UNLIKELY(txt2__array__nw_size > (uintptr_t) (message_end - message_start - txt2__value))) {
577 0 : goto error;
578 : }
579 1 : txt2__extra_size = txt2__array__mem_size + /* for alignment */ 3;
580 : }
581 :
582 : { /* txt3 */
583 : uint32_t txt2_len__value;
584 1 : pos = start + 5;
585 1 : if (SPICE_UNLIKELY(pos + 4 > message_end)) {
586 0 : goto error;
587 : }
588 1 : txt2_len__value = read_uint32(pos);
589 1 : txt3__nelements = txt2_len__value;
590 :
591 1 : txt3__nw_size = txt3__nelements;
592 1 : txt3__mem_size = sizeof(uint8_t) * txt3__nelements + sizeof(uint8_t);
593 1 : txt3__mem_size = SPICE_ALIGN(txt3__mem_size, 4);
594 1 : txt3__saved_size = txt3__nw_size;
595 : }
596 :
597 : { /* txt4 */
598 : uint16_t txt4_len__value;
599 1 : pos = start + 17 + txt3__nw_size;
600 1 : if (SPICE_UNLIKELY(pos + 2 > message_end)) {
601 0 : goto error;
602 : }
603 1 : txt4_len__value = read_uint16(pos);
604 1 : txt4__nelements = txt4_len__value;
605 :
606 1 : txt4__nw_size = txt4__nelements;
607 1 : txt4__mem_size = sizeof(uint8_t) * txt4__nelements + sizeof(uint8_t);
608 1 : txt4__mem_size = SPICE_ALIGN(txt4__mem_size, 4);
609 : }
610 :
611 1 : nw_size = 19 + txt3__nw_size + txt4__nw_size;
612 1 : mem_size = sizeof(SpiceMsgMainZeroLen1) + txt2__extra_size + txt3__mem_size + txt4__mem_size;
613 :
614 : /* Check if message fits in reported side */
615 1 : if (nw_size > (uintptr_t) (message_end - start)) {
616 0 : return NULL;
617 : }
618 :
619 : /* Validated extents and calculated size */
620 1 : data = (uint8_t *)(mem_size > UINT32_MAX ? NULL : malloc(mem_size));
621 1 : if (SPICE_UNLIKELY(data == NULL)) {
622 0 : goto error;
623 : }
624 1 : end = data + sizeof(SpiceMsgMainZeroLen1);
625 1 : in = start;
626 :
627 1 : out = (SpiceMsgMainZeroLen1 *)data;
628 :
629 1 : txt1__nelements = 4;
630 1 : memcpy(out->txt1, in, txt1__nelements);
631 : #if defined(__GNUC__)
632 : #pragma GCC diagnostic push
633 : #pragma GCC diagnostic ignored "-Wstringop-overflow"
634 : #endif
635 1 : ((char *) (out->txt1))[txt1__nelements] = 0;
636 : #if defined(__GNUC__)
637 : #pragma GCC diagnostic pop
638 : #endif
639 1 : in += txt1__nelements;
640 1 : out->sep1 = consume_uint8(&in);
641 1 : out->txt2_len = consume_uint32(&in);
642 1 : ptr_info[n_ptr].offset = consume_uint32(&in);
643 1 : ptr_info[n_ptr].parse = parse_array_uint8_terminated;
644 1 : ptr_info[n_ptr].dest = (void **)&out->txt2;
645 1 : ptr_info[n_ptr].nelements = txt2__array__nelements;
646 1 : n_ptr++;
647 1 : ptr_info[n_ptr].offset = in - start;
648 1 : ptr_info[n_ptr].parse = parse_array_uint8_terminated;
649 1 : ptr_info[n_ptr].dest = (void **)&out->txt3;
650 1 : txt3__array__nelements = out->txt2_len;
651 1 : ptr_info[n_ptr].nelements = txt3__array__nelements;
652 1 : n_ptr++;
653 1 : in += txt3__saved_size;
654 1 : out->n = consume_uint32(&in);
655 1 : out->txt4_len = consume_uint16(&in);
656 : verify(sizeof(out->txt4) == 0);
657 1 : memcpy(out->txt4, in, txt4__nelements);
658 : #if defined(__GNUC__)
659 : #pragma GCC diagnostic push
660 : #pragma GCC diagnostic ignored "-Wstringop-overflow"
661 : #endif
662 1 : ((char *) (out->txt4))[txt4__nelements] = 0;
663 : #if defined(__GNUC__)
664 : #pragma GCC diagnostic pop
665 : #endif
666 1 : in += txt4__nelements;
667 1 : end += txt4__nelements;
668 1 : end += 1;
669 :
670 1 : assert(in <= message_end);
671 :
672 3 : for (i = 0; i < n_ptr; i++) {
673 2 : if (ptr_info[i].offset == 0) {
674 0 : *ptr_info[i].dest = NULL;
675 : } else {
676 : /* Align to 32 bit */
677 2 : end = (uint8_t *)SPICE_ALIGN((uintptr_t)end, 4);
678 2 : *ptr_info[i].dest = (void *)end;
679 2 : end = ptr_info[i].parse(message_start, message_end, end, &ptr_info[i]);
680 2 : if (SPICE_UNLIKELY(end == NULL)) {
681 0 : goto error;
682 : }
683 : }
684 : }
685 :
686 1 : assert(end <= data + mem_size);
687 :
688 1 : *size = end - data;
689 1 : *free_message = (message_destructor_t) free;
690 1 : return data;
691 :
692 0 : error:
693 0 : free(data);
694 0 : return NULL;
695 : }
696 :
697 4 : static uint8_t * parse_TestChannel_msg(uint8_t *message_start, uint8_t *message_end, uint16_t message_type, SPICE_GNUC_UNUSED int minor, size_t *size_out, message_destructor_t *free_message)
698 : {
699 : static parse_msg_func_t funcs1[6] = {
700 : parse_msg_main_ShortDataSubMarshall,
701 : parse_msg_main_ArrayMessage,
702 : parse_msg_main_Zeroes,
703 : parse_msg_main_channels_list,
704 : parse_msg_main_LenMessage,
705 : parse_msg_main_ZeroLen1
706 : };
707 4 : if (message_type >= 1 && message_type < 7) {
708 4 : return funcs1[message_type-1](message_start, message_end, size_out, free_message);
709 : }
710 0 : return NULL;
711 : }
712 :
713 4 : spice_parse_channel_func_t spice_get_server_channel_parser_test(uint32_t channel, unsigned int *max_message_type)
714 : {
715 : static struct {spice_parse_channel_func_t func; unsigned int max_messages; } channels[2] = {
716 : { NULL, 0 },
717 : { parse_TestChannel_msg, 6}
718 : };
719 4 : if (channel < 2) {
720 4 : if (max_message_type != NULL) {
721 1 : *max_message_type = channels[channel].max_messages;
722 : }
723 4 : return channels[channel].func;
724 : }
725 0 : return NULL;
726 : }
727 :
728 3 : uint8_t * spice_parse_msg_test(uint8_t *message_start, uint8_t *message_end, uint32_t channel, uint16_t message_type, SPICE_GNUC_UNUSED int minor, size_t *size_out, message_destructor_t *free_message)
729 : {
730 : spice_parse_channel_func_t func;
731 3 : func = spice_get_server_channel_parser_test(channel, NULL);
732 3 : if (func != NULL) {
733 3 : return func(message_start, message_end, message_type, minor, size_out, free_message);
734 : }
735 0 : return NULL;
736 : }
|