Coverage Report

Created: 2024-02-25 07:20

/src/libfshfs/ossfuzz/volume_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libfshfs volume type
3
 *
4
 * Copyright (C) 2009-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_libfshfs.h"
31
32
#if !defined( LIBFSHFS_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
LIBFSHFS_EXTERN \
38
int libfshfs_volume_open_file_io_handle(
39
     libfshfs_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libfshfs_error_t **error );
43
44
#endif /* !defined( LIBFSHFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
2.65k
{
50
2.65k
  uint8_t string_value[ 64 ];
51
52
2.65k
  libbfio_handle_t *file_io_handle = NULL;
53
2.65k
  libfshfs_volume_t *volume        = NULL;
54
2.65k
  size_t string_size               = 0;
55
2.65k
  int result                       = 0;
56
57
2.65k
  if( libbfio_memory_range_initialize(
58
2.65k
       &file_io_handle,
59
2.65k
       NULL ) != 1 )
60
0
  {
61
0
    return( 0 );
62
0
  }
63
2.65k
  if( libbfio_memory_range_set(
64
2.65k
       file_io_handle,
65
2.65k
       (uint8_t *) data,
66
2.65k
       size,
67
2.65k
       NULL ) != 1 )
68
0
  {
69
0
    goto on_error_libbfio;
70
0
  }
71
2.65k
  if( libfshfs_volume_initialize(
72
2.65k
       &volume,
73
2.65k
       NULL ) != 1 )
74
0
  {
75
0
    goto on_error_libbfio;
76
0
  }
77
2.65k
  result = libfshfs_volume_open_file_io_handle(
78
2.65k
            volume,
79
2.65k
            file_io_handle,
80
2.65k
            LIBFSHFS_OPEN_READ,
81
2.65k
            NULL );
82
83
2.65k
  if( result != -1 )
84
616
  {
85
616
    libfshfs_volume_get_utf8_name_size(
86
616
     volume,
87
616
     &string_size,
88
616
     NULL );
89
90
616
    libfshfs_volume_get_utf8_name(
91
616
     volume,
92
616
     string_value,
93
616
     64,
94
616
     NULL );
95
96
616
    libfshfs_volume_close(
97
616
     volume,
98
616
     NULL );
99
616
  }
100
2.65k
  libfshfs_volume_free(
101
2.65k
   &volume,
102
2.65k
   NULL );
103
104
2.65k
on_error_libbfio:
105
2.65k
  libbfio_handle_free(
106
2.65k
   &file_io_handle,
107
2.65k
   NULL );
108
109
2.65k
  return( 0 );
110
2.65k
}
111
112
} /* extern "C" */
113