Debian Codegraph @

fuzz/fuzz_method_decode.c

raw symbols SCIP
1 // Copyright 2007 - 2022, Alan Antonuk and the rabbitmq-c contributors.
2 // SPDX-License-Identifier: mit
3
4 #include <errno.h>
5 #include <inttypes.h>
6 #include <math.h>
7 #include <stdarg.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include <rabbitmq-c/amqp.h>
13 #include <rabbitmq-c/framing.h>
14
15 // Drives amqp_decode_method(), the generated decoder for every AMQP method
16 // frame. The first 4 bytes are the method id (big-endian), the rest the body.
17 extern int LLVMFuzzerTestOneInput(const char *data, size_t size) {
18
19 int unused_result;
20 amqp_pool_t pool;
21 amqp_method_number_t method_id;
22
23 if (size < 4) {
24 return 0;
25 }
26
27 method_id = ((amqp_method_number_t)(uint8_t)data[0] << 24) |
28 ((amqp_method_number_t)(uint8_t)data[1] << 16) |
29 ((amqp_method_number_t)(uint8_t)data[2] << 8) |
30 ((amqp_method_number_t)(uint8_t)data[3]);
31
32 init_amqp_pool(&pool, 4096);
33 {
34 void *decoded = NULL;
35 amqp_bytes_t encoded;
36 encoded.len = size - 4;
37 encoded.bytes = (void *)(data + 4);
38
39 unused_result = amqp_decode_method(method_id, &pool, encoded, &decoded);
40 }
41 empty_amqp_pool(&pool);
42 return 0;
43 }