Coverage Report

Created: 2026-09-14 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ostree/tests/fuzz-repo.c
Line
Count
Source
1
/* Copyright 2022 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
#include "config.h"
13
14
#include "libglnx.h"
15
#include "bsdiff/bsdiff.h"
16
#include "bsdiff/bspatch.h"
17
#include <glib.h>
18
#include <stdlib.h>
19
#include <gio/gio.h>
20
#include <glib-object.h>
21
#include <libglnx.h>
22
#include <locale.h>
23
24
#include "ostree-autocleanups.h"
25
#include "ostree-types.h"
26
27
#include <string.h>
28
29
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
30
31
typedef struct
32
{
33
  GLnxTmpDir tmpdir;
34
} Fixture;
35
36
37
int
38
setup (Fixture       *fixture,
39
       gconstpointer  test_data)
40
140
{
41
140
  g_autoptr(GError) error = NULL;
42
140
  if (! glnx_mkdtemp ("test-repo-XXXXXX", 0700, &fixture->tmpdir, &error)) {
43
0
    return 1;
44
0
  }
45
140
  return 0;
46
140
}
47
48
void
49
teardown (Fixture       *fixture,
50
          gconstpointer  test_data)
51
140
{
52
 
53
140
  (void) glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL);
54
140
}
55
56
void
57
payload (Fixture         *fixture,
58
         const uint8_t   *data,
59
         size_t           size)
60
140
{
61
140
  g_autoptr (GKeyFile) config = NULL;
62
140
  g_autoptr(GError) error = NULL;
63
140
  guint64 bytes = 0;
64
65
140
  g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd,
66
140
                                                      ".",
67
140
                                                      OSTREE_REPO_MODE_ARCHIVE,
68
140
                                                      NULL,
69
140
                                                      NULL,
70
140
                                                      &error);
71
72
140
  config = ostree_repo_copy_config (repo);
73
74
140
  g_key_file_remove_key (config, "core", "min-free-space-size", NULL);
75
  
76
140
  char *m1 = malloc(size+1);
77
140
  memcpy(m1, data, size);
78
140
  m1[size] = '\0';
79
80
140
  g_key_file_set_string (config, m1, m1, m1);
81
82
140
  ostree_repo_write_config (repo, config, &error);
83
140
  ostree_repo_reload_config (repo, NULL, &error);
84
140
  ostree_repo_get_min_free_space_bytes (repo, &bytes, &error);
85
86
140
  free(m1);
87
140
}
88
89
int
90
LLVMFuzzerTestOneInput (const uint8_t *data,
91
                       size_t          size)
92
140
{
93
140
  Fixture ft;
94
140
  g_auto(GLnxTmpDir) ret_tmpdir = { 0, };
95
140
  ft.tmpdir = ret_tmpdir;
96
140
  if (setup(&ft, NULL) == 1) {
97
0
    return 0;
98
0
  }
99
100
140
  payload(&ft, data, size);
101
  teardown(&ft, NULL);
102
140
  return 0;
103
140
}