Coverage Report

Created: 2023-06-07 06:53

/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-2023, 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
717
{
50
717
  uint8_t string_value[ 64 ];
51
52
717
  libbfio_handle_t *file_io_handle = NULL;
53
717
  libfsxfs_volume_t *volume        = NULL;
54
717
  size_t string_size               = 0;
55
717
  uint8_t format_version           = 0;
56
717
  int result                       = 0;
57
58
717
  if( libbfio_memory_range_initialize(
59
717
       &file_io_handle,
60
717
       NULL ) != 1 )
61
0
  {
62
0
    return( 0 );
63
0
  }
64
717
  if( libbfio_memory_range_set(
65
717
       file_io_handle,
66
717
       (uint8_t *) data,
67
717
       size,
68
717
       NULL ) != 1 )
69
0
  {
70
0
    goto on_error_libbfio;
71
0
  }
72
717
  if( libfsxfs_volume_initialize(
73
717
       &volume,
74
717
       NULL ) != 1 )
75
0
  {
76
0
    goto on_error_libbfio;
77
0
  }
78
717
  result = libfsxfs_volume_open_file_io_handle(
79
717
            volume,
80
717
            file_io_handle,
81
717
            LIBFSXFS_OPEN_READ,
82
717
            NULL );
83
84
717
  if( result != -1 )
85
150
  {
86
150
    libfsxfs_volume_get_format_version(
87
150
     volume,
88
150
     &format_version,
89
150
     NULL );
90
91
150
    libfsxfs_volume_get_utf8_label_size(
92
150
     volume,
93
150
     &string_size,
94
150
     NULL );
95
96
150
    libfsxfs_volume_get_utf8_label(
97
150
     volume,
98
150
     string_value,
99
150
     64,
100
150
     NULL );
101
102
150
    libfsxfs_volume_close(
103
150
     volume,
104
150
     NULL );
105
150
  }
106
717
  libfsxfs_volume_free(
107
717
   &volume,
108
717
   NULL );
109
110
717
on_error_libbfio:
111
717
  libbfio_handle_free(
112
717
   &file_io_handle,
113
717
   NULL );
114
115
717
  return( 0 );
116
717
}
117
118
} /* extern "C" */
119