Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvshadow/ossfuzz/volume_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libvshadow volume 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
1.66k
{
50
1.66k
  libbfio_handle_t *file_io_handle = NULL;
51
1.66k
  libvshadow_volume_t *volume      = NULL;
52
1.66k
  int number_of_stores             = 0;
53
54
1.66k
  if( libbfio_memory_range_initialize(
55
1.66k
       &file_io_handle,
56
1.66k
       NULL ) != 1 )
57
0
  {
58
0
    return( 0 );
59
0
  }
60
1.66k
  if( libbfio_memory_range_set(
61
1.66k
       file_io_handle,
62
1.66k
       (uint8_t *) data,
63
1.66k
       size,
64
1.66k
       NULL ) != 1 )
65
0
  {
66
0
    goto on_error_libbfio;
67
0
  }
68
1.66k
  if( libvshadow_volume_initialize(
69
1.66k
       &volume,
70
1.66k
       NULL ) != 1 )
71
0
  {
72
0
    goto on_error_libbfio;
73
0
  }
74
1.66k
  if( libvshadow_volume_open_file_io_handle(
75
1.66k
       volume,
76
1.66k
       file_io_handle,
77
1.66k
       LIBVSHADOW_OPEN_READ,
78
1.66k
       NULL ) != 1 )
79
1.60k
  {
80
1.60k
    goto on_error_libvshadow;
81
1.60k
  }
82
61
  if( libvshadow_volume_get_number_of_stores(
83
61
       volume,
84
61
       &number_of_stores,
85
61
       NULL ) != 1 )
86
0
  {
87
0
    goto on_error_libvshadow;
88
0
  }
89
61
  libvshadow_volume_close(
90
61
   volume,
91
61
   NULL );
92
93
1.66k
on_error_libvshadow:
94
1.66k
  libvshadow_volume_free(
95
1.66k
   &volume,
96
1.66k
   NULL );
97
98
1.66k
on_error_libbfio:
99
1.66k
  libbfio_handle_free(
100
1.66k
   &file_io_handle,
101
1.66k
   NULL );
102
103
1.66k
  return( 0 );
104
1.66k
}
105
106
} /* extern "C" */
107