Coverage Report

Created: 2026-07-16 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/librabbitmq/fuzz/fuzz_method_decode.c
Line
Count
Source
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
5.98k
extern int LLVMFuzzerTestOneInput(const char *data, size_t size) {
18
19
5.98k
  int unused_result;
20
5.98k
  amqp_pool_t pool;
21
5.98k
  amqp_method_number_t method_id;
22
23
5.98k
  if (size < 4) {
24
3
    return 0;
25
3
  }
26
27
5.98k
  method_id = ((amqp_method_number_t)(uint8_t)data[0] << 24) |
28
5.98k
              ((amqp_method_number_t)(uint8_t)data[1] << 16) |
29
5.98k
              ((amqp_method_number_t)(uint8_t)data[2] << 8) |
30
5.98k
              ((amqp_method_number_t)(uint8_t)data[3]);
31
32
5.98k
  init_amqp_pool(&pool, 4096);
33
5.98k
  {
34
5.98k
    void *decoded = NULL;
35
5.98k
    amqp_bytes_t encoded;
36
5.98k
    encoded.len = size - 4;
37
5.98k
    encoded.bytes = (void *)(data + 4);
38
39
5.98k
    unused_result = amqp_decode_method(method_id, &pool, encoded, &decoded);
40
5.98k
  }
41
5.98k
  empty_amqp_pool(&pool);
42
5.98k
  return 0;
43
5.98k
}