Coverage Report

Created: 2026-07-10 07:32

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
3.11k
{
60
3.11k
  char string[ 64 ];
61
62
3.11k
  libbfio_handle_t *file_io_handle      = NULL;
63
3.11k
  libbfio_pool_t *file_io_pool          = NULL;
64
3.11k
  libvslvm_handle_t *handle             = NULL;
65
3.11k
  libvslvm_volume_group_t *volume_group = NULL;
66
3.11k
  size64_t extent_size                  = 0;
67
3.11k
  size_t string_size                    = 0;
68
3.11k
  uint32_t value_32bit                  = 0;
69
3.11k
  int entry_index                       = 0;
70
3.11k
  int number_of_volumes                 = 0;
71
72
3.11k
  if( libbfio_memory_range_initialize(
73
3.11k
       &file_io_handle,
74
3.11k
       NULL ) != 1 )
75
0
  {
76
0
    return( 0 );
77
0
  }
78
3.11k
  if( libbfio_memory_range_set(
79
3.11k
       file_io_handle,
80
3.11k
       (uint8_t *) data,
81
3.11k
       size,
82
3.11k
       NULL ) != 1 )
83
0
  {
84
0
    goto on_error_libbfio;
85
0
  }
86
3.11k
  if( libbfio_pool_initialize(
87
3.11k
       &file_io_pool,
88
3.11k
       0,
89
3.11k
       0,
90
3.11k
       NULL ) != 1 )
91
0
  {
92
0
    goto on_error_libbfio;
93
0
  }
94
3.11k
  if( libvslvm_handle_initialize(
95
3.11k
       &handle,
96
3.11k
       NULL ) != 1 )
97
0
  {
98
0
    goto on_error_libbfio;
99
0
  }
100
3.11k
  if( libvslvm_handle_open_file_io_handle(
101
3.11k
       handle,
102
3.11k
       file_io_handle,
103
3.11k
       LIBVSLVM_OPEN_READ,
104
3.11k
       NULL ) != 1 )
105
1.32k
  {
106
1.32k
    goto on_error_libvslvm_handle;
107
1.32k
  }
108
1.78k
  if( libbfio_pool_append_handle(
109
1.78k
       file_io_pool,
110
1.78k
       &entry_index,
111
1.78k
       file_io_handle,
112
1.78k
       LIBBFIO_OPEN_READ,
113
1.78k
       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.78k
  file_io_handle = NULL;
120
121
1.78k
  if( libvslvm_handle_open_physical_volume_files_file_io_pool(
122
1.78k
       handle,
123
1.78k
       file_io_pool,
124
1.78k
       NULL ) != 1 )
125
1.06k
  {
126
1.06k
    goto on_error_libvslvm_handle;
127
1.06k
  }
128
716
  if( libvslvm_handle_get_volume_group(
129
716
       handle,
130
716
       &volume_group,
131
716
       NULL ) == 1 )
132
716
  {
133
716
    if( libvslvm_volume_group_get_name_size(
134
716
         volume_group,
135
716
         &string_size,
136
716
         NULL ) != 1 )
137
0
    {
138
0
      goto on_error_libvslvm_volume_group;
139
0
    }
140
716
    if( libvslvm_volume_group_get_name(
141
716
         volume_group,
142
716
         string,
143
716
         64,
144
716
         NULL ) != 1 )
145
22
    {
146
22
      goto on_error_libvslvm_volume_group;
147
22
    }
148
694
    if( libvslvm_volume_group_get_identifier_size(
149
694
         volume_group,
150
694
         &string_size,
151
694
         NULL ) != 1 )
152
0
    {
153
0
      goto on_error_libvslvm_volume_group;
154
0
    }
155
694
    if( libvslvm_volume_group_get_identifier(
156
694
         volume_group,
157
694
         string,
158
694
         64,
159
694
         NULL ) != 1 )
160
0
    {
161
0
      goto on_error_libvslvm_volume_group;
162
0
    }
163
694
    if( libvslvm_volume_group_get_sequence_number(
164
694
         volume_group,
165
694
         &value_32bit,
166
694
         NULL ) != 1 )
167
0
    {
168
0
      goto on_error_libvslvm_volume_group;
169
0
    }
170
694
    if( libvslvm_volume_group_get_extent_size(
171
694
         volume_group,
172
694
         &extent_size,
173
694
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libvslvm_volume_group;
176
0
    }
177
694
    if( libvslvm_volume_group_get_number_of_physical_volumes(
178
694
         volume_group,
179
694
         &number_of_volumes,
180
694
         NULL ) != 1 )
181
0
    {
182
0
      goto on_error_libvslvm_volume_group;
183
0
    }
184
694
    if( libvslvm_volume_group_get_number_of_logical_volumes(
185
694
         volume_group,
186
694
         &number_of_volumes,
187
694
         NULL ) != 1 )
188
0
    {
189
0
      goto on_error_libvslvm_volume_group;
190
0
    }
191
716
on_error_libvslvm_volume_group:
192
716
    libvslvm_volume_group_free(
193
716
     &volume_group,
194
716
     NULL );
195
716
  }
196
716
  libvslvm_handle_close(
197
716
   handle,
198
716
   NULL );
199
200
3.11k
on_error_libvslvm_handle:
201
3.11k
  libvslvm_handle_free(
202
3.11k
   &handle,
203
3.11k
   NULL );
204
205
3.11k
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
3.11k
  if( file_io_pool != NULL )
211
3.11k
  {
212
3.11k
    libbfio_pool_free(
213
3.11k
     &file_io_pool,
214
3.11k
     NULL );
215
3.11k
  }
216
3.11k
  if( file_io_handle != NULL )
217
1.32k
  {
218
1.32k
    libbfio_handle_free(
219
1.32k
     &file_io_handle,
220
     NULL );
221
1.32k
  }
222
3.11k
  return( 0 );
223
3.11k
}
224
225
} /* extern "C" */
226