Coverage Report

Created: 2026-05-30 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fwupd/libfwupdplugin/fu-fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright 2026 Richard Hughes <richard@hughsie.com>
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
#include "config.h"
8
9
#include "fu-fuzzer.h"
10
11
134k
G_DEFINE_INTERFACE(FuFuzzer, fu_fuzzer, G_TYPE_OBJECT)
12
134k
13
134k
static void
14
134k
fu_fuzzer_default_init(FuFuzzerInterface *iface)
15
134k
{
16
45
}
17
18
/**
19
 * fu_fuzzer_test_input:
20
 * @self: a #FuFuzzer
21
 * @blob: a #GBytes
22
 * @error: (nullable): optional return location for an error
23
 *
24
 * Calls the implementation with the contents of a fuzzing buffer.
25
 *
26
 * Returns: %TRUE on success
27
 *
28
 * Since: 2.1.1
29
 */
30
gboolean
31
fu_fuzzer_test_input(FuFuzzer *self, GBytes *blob, GError **error)
32
67.0k
{
33
67.0k
  FuFuzzerInterface *iface = FU_FUZZER_GET_IFACE(self);
34
67.0k
  if (iface->test_input == NULL) {
35
0
    g_set_error_literal(error,
36
0
            FWUPD_ERROR,
37
0
            FWUPD_ERROR_NOT_SUPPORTED,
38
0
            "FuFuzzer->test_input() not implemented");
39
0
    return FALSE;
40
0
  }
41
67.0k
  return iface->test_input(self, blob, error);
42
67.0k
}
43
44
/**
45
 * fu_fuzzer_build_example:
46
 * @self: a #FuFuzzer
47
 * @blob: a #GBytes to use as an input buffer, or %NULL
48
 * @error: (nullable): optional return location for an error
49
 *
50
 * Builds a sample corpus used for fuzzing.
51
 *
52
 * Returns: (transfer full): a #GBytes on success
53
 *
54
 * Since: 2.1.1
55
 */
56
GBytes *
57
fu_fuzzer_build_example(FuFuzzer *self, GBytes *blob, GError **error)
58
0
{
59
0
  FuFuzzerInterface *iface = FU_FUZZER_GET_IFACE(self);
60
0
  if (iface->build_example == NULL) {
61
0
    g_set_error_literal(error,
62
0
            FWUPD_ERROR,
63
0
            FWUPD_ERROR_NOT_SUPPORTED,
64
0
            "FuFuzzer->build_example() not implemented");
65
0
    return NULL;
66
0
  }
67
0
  return iface->build_example(self, blob, error);
68
0
}