Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvslvm/ossfuzz/volume_group_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvslvm volume group type
3
 *
4
 * Copyright (C) 2014-2026, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
/* Note that some of the OSS-Fuzz engines use C++
26
 */
27
extern "C" {
28
29
#include "ossfuzz_libbfio.h"
30
#include "ossfuzz_libvslvm.h"
31
32
#if !defined( LIBVSLVM_HAVE_BFIO )
33
34
/* Opens a handle using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBVSLVM_EXTERN \
38
int libvslvm_handle_open_file_io_handle(
39
     libvslvm_handle_t *handle,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libvslvm_error_t **error );
43
44
/* Opens the physical volume files
45
 * This function assumes the physical volume files are in same order as defined by the metadata
46
 * Returns 1 if successful or -1 on error
47
 */
48
LIBVSLVM_EXTERN \
49
int libvslvm_handle_open_physical_volume_files_file_io_pool(
50
     libvslvm_handle_t *handle,
51
     libbfio_pool_t *file_io_pool,
52
     libvslvm_error_t **error );
53
54
#endif /* !defined( LIBVSLVM_HAVE_BFIO ) */
55
56
int LLVMFuzzerTestOneInput(
57
     const uint8_t *data,
58
     size_t size )
59
2.99k
{
60
2.99k
  char string[ 64 ];
61
62
2.99k
  libbfio_handle_t *file_io_handle      = NULL;
63
2.99k
  libbfio_pool_t *file_io_pool          = NULL;
64
2.99k
  libvslvm_handle_t *handle             = NULL;
65
2.99k
  libvslvm_volume_group_t *volume_group = NULL;
66
2.99k
  size64_t extent_size                  = 0;
67
2.99k
  size_t string_size                    = 0;
68
2.99k
  uint32_t value_32bit                  = 0;
69
2.99k
  int entry_index                       = 0;
70
2.99k
  int number_of_volumes                 = 0;
71
72
2.99k
  if( libbfio_memory_range_initialize(
73
2.99k
       &file_io_handle,
74
2.99k
       NULL ) != 1 )
75
0
  {
76
0
    return( 0 );
77
0
  }
78
2.99k
  if( libbfio_memory_range_set(
79
2.99k
       file_io_handle,
80
2.99k
       (uint8_t *) data,
81
2.99k
       size,
82
2.99k
       NULL ) != 1 )
83
0
  {
84
0
    goto on_error_libbfio;
85
0
  }
86
2.99k
  if( libbfio_pool_initialize(
87
2.99k
       &file_io_pool,
88
2.99k
       0,
89
2.99k
       0,
90
2.99k
       NULL ) != 1 )
91
0
  {
92
0
    goto on_error_libbfio;
93
0
  }
94
2.99k
  if( libvslvm_handle_initialize(
95
2.99k
       &handle,
96
2.99k
       NULL ) != 1 )
97
0
  {
98
0
    goto on_error_libbfio;
99
0
  }
100
2.99k
  if( libvslvm_handle_open_file_io_handle(
101
2.99k
       handle,
102
2.99k
       file_io_handle,
103
2.99k
       LIBVSLVM_OPEN_READ,
104
2.99k
       NULL ) != 1 )
105
1.27k
  {
106
1.27k
    goto on_error_libvslvm_handle;
107
1.27k
  }
108
1.71k
  if( libbfio_pool_append_handle(
109
1.71k
       file_io_pool,
110
1.71k
       &entry_index,
111
1.71k
       file_io_handle,
112
1.71k
       LIBBFIO_OPEN_READ,
113
1.71k
       NULL ) != 1 )
114
0
  {
115
0
    goto on_error_libvslvm_handle;
116
0
  }
117
  /* The file IO pool takes over management of the file IO handle
118
   */
119
1.71k
  file_io_handle = NULL;
120
121
1.71k
  if( libvslvm_handle_open_physical_volume_files_file_io_pool(
122
1.71k
       handle,
123
1.71k
       file_io_pool,
124
1.71k
       NULL ) != 1 )
125
1.25k
  {
126
1.25k
    goto on_error_libvslvm_handle;
127
1.25k
  }
128
463
  if( libvslvm_handle_get_volume_group(
129
463
       handle,
130
463
       &volume_group,
131
463
       NULL ) == 1 )
132
463
  {
133
463
    if( libvslvm_volume_group_get_name_size(
134
463
         volume_group,
135
463
         &string_size,
136
463
         NULL ) != 1 )
137
0
    {
138
0
      goto on_error_libvslvm_volume_group;
139
0
    }
140
463
    if( libvslvm_volume_group_get_name(
141
463
         volume_group,
142
463
         string,
143
463
         64,
144
463
         NULL ) != 1 )
145
16
    {
146
16
      goto on_error_libvslvm_volume_group;
147
16
    }
148
447
    if( libvslvm_volume_group_get_identifier_size(
149
447
         volume_group,
150
447
         &string_size,
151
447
         NULL ) != 1 )
152
0
    {
153
0
      goto on_error_libvslvm_volume_group;
154
0
    }
155
447
    if( libvslvm_volume_group_get_identifier(
156
447
         volume_group,
157
447
         string,
158
447
         64,
159
447
         NULL ) != 1 )
160
0
    {
161
0
      goto on_error_libvslvm_volume_group;
162
0
    }
163
447
    if( libvslvm_volume_group_get_sequence_number(
164
447
         volume_group,
165
447
         &value_32bit,
166
447
         NULL ) != 1 )
167
0
    {
168
0
      goto on_error_libvslvm_volume_group;
169
0
    }
170
447
    if( libvslvm_volume_group_get_extent_size(
171
447
         volume_group,
172
447
         &extent_size,
173
447
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libvslvm_volume_group;
176
0
    }
177
447
    if( libvslvm_volume_group_get_number_of_physical_volumes(
178
447
         volume_group,
179
447
         &number_of_volumes,
180
447
         NULL ) != 1 )
181
0
    {
182
0
      goto on_error_libvslvm_volume_group;
183
0
    }
184
447
    if( libvslvm_volume_group_get_number_of_logical_volumes(
185
447
         volume_group,
186
447
         &number_of_volumes,
187
447
         NULL ) != 1 )
188
0
    {
189
0
      goto on_error_libvslvm_volume_group;
190
0
    }
191
463
on_error_libvslvm_volume_group:
192
463
    libvslvm_volume_group_free(
193
463
     &volume_group,
194
463
     NULL );
195
463
  }
196
463
  libvslvm_handle_close(
197
463
   handle,
198
463
   NULL );
199
200
2.99k
on_error_libvslvm_handle:
201
2.99k
  libvslvm_handle_free(
202
2.99k
   &handle,
203
2.99k
   NULL );
204
205
2.99k
on_error_libbfio:
206
  /* Note that on error the handle still has a reference to file_io_pool
207
   * that will be closed. Therefore the file IO pool and handle need to
208
   * be freed after closing or freeing the handle.
209
   */
210
2.99k
  if( file_io_pool != NULL )
211
2.99k
  {
212
2.99k
    libbfio_pool_free(
213
2.99k
     &file_io_pool,
214
2.99k
     NULL );
215
2.99k
  }
216
2.99k
  if( file_io_handle != NULL )
217
1.27k
  {
218
1.27k
    libbfio_handle_free(
219
1.27k
     &file_io_handle,
220
     NULL );
221
1.27k
  }
222
2.99k
  return( 0 );
223
2.99k
}
224
225
} /* extern "C" */
226