| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <errno.h> |
| 5 |
#include <inttypes.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
#include <rabbitmq-c/amqp.h> |
| 11 |
#include <rabbitmq-c/framing.h> |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
extern int LLVMFuzzerTestOneInput(const char *data, size_t size) { |
| 16 |
|
| 17 |
amqp_connection_state_t conn; |
| 18 |
amqp_bytes_t buffer; |
| 19 |
size_t iterations = 0; |
| 20 |
|
| 21 |
if (size == 0) { |
| 22 |
return 0; |
| 23 |
} |
| 24 |
|
| 25 |
conn = amqp_new_connection(); |
| 26 |
if (conn == NULL) { |
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
buffer.bytes = (void *)data; |
| 31 |
buffer.len = size; |
| 32 |
|
| 33 |
while (buffer.len > 0 && iterations < 4096) { |
| 34 |
amqp_frame_t frame; |
| 35 |
int res; |
| 36 |
|
| 37 |
memset(&frame, 0, sizeof(frame)); |
| 38 |
res = amqp_handle_input(conn, buffer, &frame); |
| 39 |
if (res <= 0) { |
| 40 |
break; |
| 41 |
} |
| 42 |
|
| 43 |
buffer.bytes = (void *)((const char *)buffer.bytes + (size_t)res); |
| 44 |
buffer.len -= (size_t)res; |
| 45 |
|
| 46 |
if (frame.frame_type != 0) { |
| 47 |
amqp_maybe_release_buffers_on_channel(conn, frame.channel); |
| 48 |
} |
| 49 |
|
| 50 |
iterations++; |
| 51 |
} |
| 52 |
|
| 53 |
amqp_destroy_connection(conn); |
| 54 |
return 0; |
| 55 |
} |