Coverage Report

Created: 2024-02-25 07:19

/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
1.31k
{
50
1.31k
  uint8_t string_value[ 64 ];
51
52
1.31k
  libbfio_handle_t *file_io_handle = NULL;
53
1.31k
  libfshfs_volume_t *volume        = NULL;
54
1.31k
  size_t string_size               = 0;
55
1.31k
  int result                       = 0;
56
57
1.31k
  if( libbfio_memory_range_initialize(
58
1.31k
       &file_io_handle,
59
1.31k
       NULL ) != 1 )
60
0
  {
61
0
    return( 0 );
62
0
  }
63
1.31k
  if( libbfio_memory_range_set(
64
1.31k
       file_io_handle,
65
1.31k
       (uint8_t *) data,
66
1.31k
       size,
67
1.31k
       NULL ) != 1 )
68
0
  {
69
0
    goto on_error_libbfio;
70
0
  }
71
1.31k
  if( libfshfs_volume_initialize(
72
1.31k
       &volume,
73
1.31k
       NULL ) != 1 )
74
0
  {
75
0
    goto on_error_libbfio;
76
0
  }
77
1.31k
  result = libfshfs_volume_open_file_io_handle(
78
1.31k
            volume,
79
1.31k
            file_io_handle,
80
1.31k
            LIBFSHFS_OPEN_READ,
81
1.31k
            NULL );
82
83
1.31k
  if( result != -1 )
84
346
  {
85
346
    libfshfs_volume_get_utf8_name_size(
86
346
     volume,
87
346
     &string_size,
88
346
     NULL );
89
90
346
    libfshfs_volume_get_utf8_name(
91
346
     volume,
92
346
     string_value,
93
346
     64,
94
346
     NULL );
95
96
346
    libfshfs_volume_close(
97
346
     volume,
98
346
     NULL );
99
346
  }
100
1.31k
  libfshfs_volume_free(
101
1.31k
   &volume,
102
1.31k
   NULL );
103
104
1.31k
on_error_libbfio:
105
1.31k
  libbfio_handle_free(
106
1.31k
   &file_io_handle,
107
1.31k
   NULL );
108
109
1.31k
  return( 0 );
110
1.31k
}
111
112
} /* extern "C" */
113