Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvshadow/ossfuzz/store_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvshadow store type
3
 *
4
 * Copyright (C) 2011-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_libvshadow.h"
31
32
#if !defined( LIBVSHADOW_HAVE_BFIO )
33
34
/* Opens a volume using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBVSHADOW_EXTERN \
38
int libvshadow_volume_open_file_io_handle(
39
     libvshadow_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libvshadow_error_t **error );
43
44
#endif /* !defined( LIBVSHADOW_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
2.95k
{
50
2.95k
  uint8_t buffer[ 512 ];
51
2.95k
  uint8_t guid[ 16 ];
52
53
2.95k
  libbfio_handle_t *file_io_handle = NULL;
54
2.95k
  libvshadow_store_t *store        = NULL;
55
2.95k
  libvshadow_volume_t *volume      = NULL;
56
2.95k
  off64_t volume_offset            = 0;
57
2.95k
  size64_t volume_size             = 0;
58
2.95k
  uint64_t value_64bit             = 0;
59
2.95k
  uint32_t value_32bit             = 0;
60
2.95k
  int number_of_blocks             = 0;
61
2.95k
  int number_of_stores             = 0;
62
2.95k
  int read_iterator                = 0;
63
64
2.95k
  if( libbfio_memory_range_initialize(
65
2.95k
       &file_io_handle,
66
2.95k
       NULL ) != 1 )
67
0
  {
68
0
    return( 0 );
69
0
  }
70
2.95k
  if( libbfio_memory_range_set(
71
2.95k
       file_io_handle,
72
2.95k
       (uint8_t *) data,
73
2.95k
       size,
74
2.95k
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
2.95k
  if( libvshadow_volume_initialize(
79
2.95k
       &volume,
80
2.95k
       NULL ) != 1 )
81
0
  {
82
0
    goto on_error_libbfio;
83
0
  }
84
2.95k
  if( libvshadow_volume_open_file_io_handle(
85
2.95k
       volume,
86
2.95k
       file_io_handle,
87
2.95k
       LIBVSHADOW_OPEN_READ,
88
2.95k
       NULL ) != 1 )
89
1.88k
  {
90
1.88k
    goto on_error_libvshadow_volume;
91
1.88k
  }
92
1.06k
  if( libvshadow_volume_get_number_of_stores(
93
1.06k
       volume,
94
1.06k
       &number_of_stores,
95
1.06k
       NULL ) != 1 )
96
0
  {
97
0
    goto on_error_libvshadow_volume;
98
0
  }
99
1.06k
  if( number_of_stores > 0 )
100
1.00k
  {
101
1.00k
    if( libvshadow_volume_get_store_identifier(
102
1.00k
         volume,
103
1.00k
         0,
104
1.00k
         guid,
105
1.00k
         16,
106
1.00k
         NULL ) != 1 )
107
0
    {
108
0
      goto on_error_libvshadow_volume;
109
0
    }
110
1.00k
    if( libvshadow_volume_get_store(
111
1.00k
         volume,
112
1.00k
         0,
113
1.00k
         &store,
114
1.00k
         NULL ) != 1 )
115
0
    {
116
0
      goto on_error_libvshadow_volume;
117
0
    }
118
1.00k
    if( libvshadow_store_get_identifier(
119
1.00k
         store,
120
1.00k
         guid,
121
1.00k
         16,
122
1.00k
         NULL ) != 1 )
123
0
    {
124
0
      goto on_error_libvshadow_store;
125
0
    }
126
1.00k
    if( libvshadow_store_get_creation_time(
127
1.00k
         store,
128
1.00k
         &value_64bit,
129
1.00k
         NULL ) != 1 )
130
0
    {
131
0
      goto on_error_libvshadow_store;
132
0
    }
133
1.00k
    if( libvshadow_store_get_copy_identifier(
134
1.00k
         store,
135
1.00k
         guid,
136
1.00k
         16,
137
1.00k
         NULL ) != 1 )
138
7
    {
139
7
      goto on_error_libvshadow_store;
140
7
    }
141
997
    if( libvshadow_store_get_copy_set_identifier(
142
997
         store,
143
997
         guid,
144
997
         16,
145
997
         NULL ) != 1 )
146
0
    {
147
0
      goto on_error_libvshadow_store;
148
0
    }
149
997
    if( libvshadow_store_get_attribute_flags(
150
997
         store,
151
997
         &value_32bit,
152
997
         NULL ) != 1 )
153
0
    {
154
0
      goto on_error_libvshadow_store;
155
0
    }
156
997
    if( libvshadow_store_get_number_of_blocks(
157
997
         store,
158
997
         &number_of_blocks,
159
997
         NULL ) != 1 )
160
686
    {
161
686
      goto on_error_libvshadow_store;
162
686
    }
163
311
    if( libvshadow_store_get_size(
164
311
         store,
165
311
         &value_64bit,
166
311
         NULL ) != 1 )
167
0
    {
168
0
      goto on_error_libvshadow_store;
169
0
    }
170
311
    if( libvshadow_store_get_volume_size(
171
311
         store,
172
311
         &volume_size,
173
311
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libvshadow_store;
176
0
    }
177
311
    for( read_iterator = 0;
178
8.84k
         read_iterator < 128;
179
8.53k
         read_iterator++ )
180
8.84k
    {
181
8.84k
      if( volume_offset >= volume_size )
182
34
      {
183
34
        break;
184
34
      }
185
8.80k
      if( libvshadow_store_read_buffer_at_offset(
186
8.80k
           store,
187
8.80k
           buffer,
188
8.80k
           497,
189
8.80k
           volume_offset,
190
8.80k
           NULL ) == -1 )
191
270
      {
192
270
        goto on_error_libvshadow_store;
193
270
      }
194
8.53k
      volume_offset += 497;
195
8.53k
    }
196
1.00k
on_error_libvshadow_store:
197
1.00k
    libvshadow_store_free(
198
1.00k
     &store,
199
1.00k
     NULL );
200
1.00k
  }
201
1.06k
  libvshadow_volume_close(
202
1.06k
   volume,
203
1.06k
   NULL );
204
205
2.95k
on_error_libvshadow_volume:
206
2.95k
  libvshadow_volume_free(
207
2.95k
   &volume,
208
2.95k
   NULL );
209
210
2.95k
on_error_libbfio:
211
2.95k
  libbfio_handle_free(
212
2.95k
   &file_io_handle,
213
2.95k
   NULL );
214
215
2.95k
  return( 0 );
216
2.95k
}
217
218
} /* extern "C" */
219