Coverage Report

Created: 2024-11-21 06:05

/src/protobuf-c-fuzzers/fuzzer.cpp
Line
Count
Source
1
/* 2019 Guido Vranken <guidovranken@gmail.com> */
2
3
#include <assert.h>
4
#include <stdlib.h>
5
#include <fuzzing/memory.hpp>
6
#include "test-full.pb-c.h"
7
8
#define X(OBJ, PREFIX) \
9
20.2k
    { \
10
20.2k
        OBJ* msg = PREFIX##__unpack(NULL, size, data); \
11
20.2k
        if ( msg != NULL ) { \
12
5.00k
            const size_t len = PREFIX##__get_packed_size(msg); \
13
5.00k
            uint8_t* copy = (uint8_t*)malloc(len); \
14
5.00k
            PREFIX##__pack(msg, copy); \
15
5.00k
            fuzzing::memory::memory_test(copy, len); \
16
5.00k
            free(copy); \
17
5.00k
        } \
18
20.2k
        PREFIX##__free_unpacked(msg, NULL); \
19
20.2k
    }
20
21
6.76k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
22
6.76k
    X(Foo__TestMessSubMess, foo__test_mess_sub_mess);
23
6.76k
    X(Foo__TestFieldFlags, foo__test_field_flags);
24
6.76k
    X(Foo__TestMessageCheck, foo__test_message_check);
25
6.76k
    return 0;
26
6.76k
}