Coverage Report

Created: 2023-06-07 06:14

/src/p11-kit/fuzz/rpc_fuzzer.c
Line
Count
Source
1
/*
2
# Copyright 2016 Google Inc.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#      http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
#
16
################################################################################
17
*/
18
19
#include "config.h"
20
#include "test.h"
21
22
#include "fuzz/fuzz.h"
23
#include "library.h"
24
#include "mock.h"
25
#include "p11-kit/rpc.h"
26
27
#include <assert.h>
28
29
static p11_virtual base;
30
31
#ifdef __cplusplus
32
extern "C"
33
#endif
34
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
35
36
{
36
36
    p11_buffer buffer;
37
38
36
    mock_module_init ();
39
36
    p11_library_init ();
40
41
36
    p11_buffer_init (&buffer, 0);
42
43
36
    p11_virtual_init (&base, &p11_virtual_base, &mock_module_no_slots, NULL);
44
36
    base.funcs.C_Initialize (&base.funcs, NULL);
45
46
36
    p11_buffer_add (&buffer, data, size);
47
36
    assert (!p11_buffer_failed (&buffer));
48
49
36
    p11_rpc_server_handle (&base.funcs, &buffer, &buffer);
50
51
36
    p11_buffer_uninit (&buffer);
52
36
    mock_module_reset ();
53
36
    p11_library_uninit ();
54
55
36
    return 0;
56
36
}