Coverage Report

Created: 2023-06-07 06:53

/src/libfsxfs/ossfuzz/file_entry_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libfsxfs file_entry 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
7.11k
{
50
7.11k
  uint8_t string_value[ 64 ];
51
52
7.11k
  libbfio_handle_t *file_io_handle      = NULL;
53
7.11k
  libfsxfs_file_entry_t *root_directory = NULL;
54
7.11k
  libfsxfs_file_entry_t *sub_file_entry = NULL;
55
7.11k
  libfsxfs_volume_t *volume             = NULL;
56
7.11k
  size64_t file_size                    = 0;
57
7.11k
  size_t string_size                    = 0;
58
7.11k
  off64_t file_offset                   = 0;
59
7.11k
  uint64_t value_64bit                  = 0;
60
7.11k
  int64_t posix_time                    = 0;
61
7.11k
  uint32_t major_device_number          = 0;
62
7.11k
  uint32_t minor_device_number          = 0;
63
7.11k
  uint32_t value_32bit                  = 0;
64
7.11k
  uint16_t value_16bit                  = 0;
65
7.11k
  int number_of_extents                 = 0;
66
7.11k
  int number_of_sub_file_entries        = 0;
67
7.11k
  int result                            = 0;
68
69
7.11k
  if( libbfio_memory_range_initialize(
70
7.11k
       &file_io_handle,
71
7.11k
       NULL ) != 1 )
72
0
  {
73
0
    return( 0 );
74
0
  }
75
7.11k
  if( libbfio_memory_range_set(
76
7.11k
       file_io_handle,
77
7.11k
       (uint8_t *) data,
78
7.11k
       size,
79
7.11k
       NULL ) != 1 )
80
0
  {
81
0
    goto on_error_libbfio;
82
0
  }
83
7.11k
  if( libfsxfs_volume_initialize(
84
7.11k
       &volume,
85
7.11k
       NULL ) != 1 )
86
0
  {
87
0
    goto on_error_libbfio;
88
0
  }
89
7.11k
  if( libfsxfs_volume_open_file_io_handle(
90
7.11k
       volume,
91
7.11k
       file_io_handle,
92
7.11k
       LIBFSXFS_OPEN_READ,
93
7.11k
       NULL ) != 1 )
94
1.73k
  {
95
1.73k
    goto on_error_libfsxfs_volume;
96
1.73k
  }
97
5.37k
  if( libfsxfs_volume_get_root_directory(
98
5.37k
       volume,
99
5.37k
       &root_directory,
100
5.37k
       NULL ) == 1 )
101
3.62k
  {
102
3.62k
    if( libfsxfs_file_entry_get_number_of_sub_file_entries(
103
3.62k
         root_directory,
104
3.62k
         &number_of_sub_file_entries,
105
3.62k
         NULL ) != 1 )
106
722
    {
107
722
      goto on_error_libfsxfs_root_directory;
108
722
    }
109
2.90k
    if( number_of_sub_file_entries > 0 )
110
2.58k
    {
111
2.58k
      result = libfsxfs_file_entry_get_sub_file_entry_by_index(
112
2.58k
                root_directory,
113
2.58k
                0,
114
2.58k
                &sub_file_entry,
115
2.58k
                NULL );
116
117
2.58k
      if( result != -1 )
118
2.05k
      {
119
2.05k
        libfsxfs_file_entry_get_inode_number(
120
2.05k
         sub_file_entry,
121
2.05k
         &value_64bit,
122
2.05k
         NULL );
123
124
2.05k
        libfsxfs_file_entry_get_creation_time(
125
2.05k
         sub_file_entry,
126
2.05k
         &posix_time,
127
2.05k
         NULL );
128
129
2.05k
        libfsxfs_file_entry_get_modification_time(
130
2.05k
         sub_file_entry,
131
2.05k
         &posix_time,
132
2.05k
         NULL );
133
134
2.05k
        libfsxfs_file_entry_get_access_time(
135
2.05k
         sub_file_entry,
136
2.05k
         &posix_time,
137
2.05k
         NULL );
138
139
2.05k
        libfsxfs_file_entry_get_inode_change_time(
140
2.05k
         sub_file_entry,
141
2.05k
         &posix_time,
142
2.05k
         NULL );
143
144
2.05k
        libfsxfs_file_entry_get_file_mode(
145
2.05k
         sub_file_entry,
146
2.05k
         &value_16bit,
147
2.05k
         NULL );
148
149
2.05k
        libfsxfs_file_entry_get_number_of_links(
150
2.05k
         sub_file_entry,
151
2.05k
         &value_32bit,
152
2.05k
         NULL );
153
154
2.05k
        libfsxfs_file_entry_get_owner_identifier(
155
2.05k
         sub_file_entry,
156
2.05k
         &value_32bit,
157
2.05k
         NULL );
158
159
2.05k
        libfsxfs_file_entry_get_group_identifier(
160
2.05k
         sub_file_entry,
161
2.05k
         &value_32bit,
162
2.05k
         NULL );
163
164
2.05k
        libfsxfs_file_entry_get_device_identifier(
165
2.05k
         sub_file_entry,
166
2.05k
         &value_32bit,
167
2.05k
         NULL );
168
169
2.05k
        libfsxfs_file_entry_get_device_number(
170
2.05k
         sub_file_entry,
171
2.05k
         &major_device_number,
172
2.05k
         &minor_device_number,
173
2.05k
         NULL );
174
175
2.05k
        libfsxfs_file_entry_get_utf8_name_size(
176
2.05k
         sub_file_entry,
177
2.05k
         &string_size,
178
2.05k
         NULL );
179
180
2.05k
        libfsxfs_file_entry_get_utf8_name(
181
2.05k
         sub_file_entry,
182
2.05k
         string_value,
183
2.05k
         64,
184
2.05k
         NULL );
185
186
2.05k
        libfsxfs_file_entry_get_utf8_symbolic_link_target_size(
187
2.05k
         sub_file_entry,
188
2.05k
         &string_size,
189
2.05k
         NULL );
190
191
2.05k
        libfsxfs_file_entry_get_utf8_symbolic_link_target(
192
2.05k
         sub_file_entry,
193
2.05k
         string_value,
194
2.05k
         64,
195
2.05k
         NULL );
196
197
2.05k
        libfsxfs_file_entry_get_offset(
198
2.05k
         sub_file_entry,
199
2.05k
         &file_offset,
200
2.05k
         NULL );
201
202
2.05k
        libfsxfs_file_entry_get_size(
203
2.05k
         sub_file_entry,
204
2.05k
         &file_size,
205
2.05k
         NULL );
206
207
2.05k
        libfsxfs_file_entry_get_number_of_extents(
208
2.05k
         sub_file_entry,
209
2.05k
         &number_of_extents,
210
2.05k
         NULL );
211
2.05k
      }
212
2.58k
      libfsxfs_file_entry_free(
213
2.58k
       &sub_file_entry,
214
2.58k
       NULL );
215
2.58k
    }
216
3.62k
on_error_libfsxfs_root_directory:
217
3.62k
    libfsxfs_file_entry_free(
218
3.62k
     &root_directory,
219
3.62k
     NULL );
220
3.62k
  }
221
5.37k
  libfsxfs_volume_close(
222
5.37k
   volume,
223
5.37k
   NULL );
224
225
7.11k
on_error_libfsxfs_volume:
226
7.11k
  libfsxfs_volume_free(
227
7.11k
   &volume,
228
7.11k
   NULL );
229
230
7.11k
on_error_libbfio:
231
7.11k
  libbfio_handle_free(
232
7.11k
   &file_io_handle,
233
7.11k
   NULL );
234
235
7.11k
  return( 0 );
236
7.11k
}
237
238
} /* extern "C" */
239