Coverage Report

Created: 2025-06-13 07:21

/src/libfsxfs/ossfuzz/volume_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libfsxfs volume type
3
 *
4
 * Copyright (C) 2020-2024, 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_libfsxfs.h"
31
32
#if !defined( LIBFSXFS_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
LIBFSXFS_EXTERN \
38
int libfsxfs_volume_open_file_io_handle(
39
     libfsxfs_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libfsxfs_error_t **error );
43
44
#endif /* !defined( LIBFSXFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
594
{
50
594
  uint8_t string_value[ 64 ];
51
52
594
  libbfio_handle_t *file_io_handle = NULL;
53
594
  libfsxfs_volume_t *volume        = NULL;
54
594
  size_t string_size               = 0;
55
594
  uint8_t format_version           = 0;
56
594
  int result                       = 0;
57
58
594
  if( libbfio_memory_range_initialize(
59
594
       &file_io_handle,
60
594
       NULL ) != 1 )
61
0
  {
62
0
    return( 0 );
63
0
  }
64
594
  if( libbfio_memory_range_set(
65
594
       file_io_handle,
66
594
       (uint8_t *) data,
67
594
       size,
68
594
       NULL ) != 1 )
69
0
  {
70
0
    goto on_error_libbfio;
71
0
  }
72
594
  if( libfsxfs_volume_initialize(
73
594
       &volume,
74
594
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
594
  result = libfsxfs_volume_open_file_io_handle(
79
594
            volume,
80
594
            file_io_handle,
81
594
            LIBFSXFS_OPEN_READ,
82
594
            NULL );
83
84
594
  if( result != -1 )
85
115
  {
86
115
    libfsxfs_volume_get_format_version(
87
115
     volume,
88
115
     &format_version,
89
115
     NULL );
90
91
115
    libfsxfs_volume_get_utf8_label_size(
92
115
     volume,
93
115
     &string_size,
94
115
     NULL );
95
96
115
    libfsxfs_volume_get_utf8_label(
97
115
     volume,
98
115
     string_value,
99
115
     64,
100
115
     NULL );
101
102
115
    libfsxfs_volume_close(
103
115
     volume,
104
115
     NULL );
105
115
  }
106
594
  libfsxfs_volume_free(
107
594
   &volume,
108
594
   NULL );
109
110
594
on_error_libbfio:
111
594
  libbfio_handle_free(
112
594
   &file_io_handle,
113
594
   NULL );
114
115
594
  return( 0 );
116
594
}
117
118
} /* extern "C" */
119