Coverage Report

Created: 2023-06-07 06:53

/src/libfsext/ossfuzz/file_entry_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libfsext file_entry type
3
 *
4
 * Copyright (C) 2010-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_libfsext.h"
31
32
#if !defined( LIBFSEXT_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
LIBFSEXT_EXTERN \
38
int libfsext_volume_open_file_io_handle(
39
     libfsext_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libfsext_error_t **error );
43
44
#endif /* !defined( LIBFSEXT_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
  libfsext_file_entry_t *root_directory = NULL;
54
7.11k
  libfsext_file_entry_t *sub_file_entry = NULL;
55
7.11k
  libfsext_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
  int64_t posix_time_64bit              = 0;
60
7.11k
  uint32_t value_32bit                  = 0;
61
7.11k
  int32_t posix_time_32bit              = 0;
62
7.11k
  uint16_t value_16bit                  = 0;
63
7.11k
  uint8_t major_device_number           = 0;
64
7.11k
  uint8_t minor_device_number           = 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( libfsext_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( libfsext_volume_open_file_io_handle(
90
7.11k
       volume,
91
7.11k
       file_io_handle,
92
7.11k
       LIBFSEXT_OPEN_READ,
93
7.11k
       NULL ) != 1 )
94
1.73k
  {
95
1.73k
    goto on_error_libfsext_volume;
96
1.73k
  }
97
5.37k
  if( libfsext_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( libfsext_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_libfsext_root_directory;
108
722
    }
109
2.90k
    if( number_of_sub_file_entries > 0 )
110
2.58k
    {
111
2.58k
      result = libfsext_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
        libfsext_file_entry_get_inode_number(
120
2.05k
         sub_file_entry,
121
2.05k
         &value_32bit,
122
2.05k
         NULL );
123
124
2.05k
        libfsext_file_entry_get_creation_time(
125
2.05k
         sub_file_entry,
126
2.05k
         &posix_time_64bit,
127
2.05k
         NULL );
128
129
2.05k
        libfsext_file_entry_get_modification_time(
130
2.05k
         sub_file_entry,
131
2.05k
         &posix_time_64bit,
132
2.05k
         NULL );
133
134
2.05k
        libfsext_file_entry_get_access_time(
135
2.05k
         sub_file_entry,
136
2.05k
         &posix_time_64bit,
137
2.05k
         NULL );
138
139
2.05k
        libfsext_file_entry_get_inode_change_time(
140
2.05k
         sub_file_entry,
141
2.05k
         &posix_time_64bit,
142
2.05k
         NULL );
143
144
2.05k
        libfsext_file_entry_get_deletion_time(
145
2.05k
         sub_file_entry,
146
2.05k
         &posix_time_32bit,
147
2.05k
         NULL );
148
149
2.05k
        libfsext_file_entry_get_file_mode(
150
2.05k
         sub_file_entry,
151
2.05k
         &value_16bit,
152
2.05k
         NULL );
153
154
2.05k
        libfsext_file_entry_get_number_of_links(
155
2.05k
         sub_file_entry,
156
2.05k
         &value_16bit,
157
2.05k
         NULL );
158
159
2.05k
        libfsext_file_entry_get_owner_identifier(
160
2.05k
         sub_file_entry,
161
2.05k
         &value_32bit,
162
2.05k
         NULL );
163
164
2.05k
        libfsext_file_entry_get_group_identifier(
165
2.05k
         sub_file_entry,
166
2.05k
         &value_32bit,
167
2.05k
         NULL );
168
169
2.05k
        libfsext_file_entry_get_device_identifier(
170
2.05k
         sub_file_entry,
171
2.05k
         &value_32bit,
172
2.05k
         NULL );
173
174
2.05k
        libfsext_file_entry_get_device_number(
175
2.05k
         sub_file_entry,
176
2.05k
         &major_device_number,
177
2.05k
         &minor_device_number,
178
2.05k
         NULL );
179
180
2.05k
        libfsext_file_entry_get_utf8_name_size(
181
2.05k
         sub_file_entry,
182
2.05k
         &string_size,
183
2.05k
         NULL );
184
185
2.05k
        libfsext_file_entry_get_utf8_name(
186
2.05k
         sub_file_entry,
187
2.05k
         string_value,
188
2.05k
         64,
189
2.05k
         NULL );
190
191
2.05k
        libfsext_file_entry_get_utf8_symbolic_link_target_size(
192
2.05k
         sub_file_entry,
193
2.05k
         &string_size,
194
2.05k
         NULL );
195
196
2.05k
        libfsext_file_entry_get_utf8_symbolic_link_target(
197
2.05k
         sub_file_entry,
198
2.05k
         string_value,
199
2.05k
         64,
200
2.05k
         NULL );
201
202
2.05k
        libfsext_file_entry_get_offset(
203
2.05k
         sub_file_entry,
204
2.05k
         &file_offset,
205
2.05k
         NULL );
206
207
2.05k
        libfsext_file_entry_get_size(
208
2.05k
         sub_file_entry,
209
2.05k
         &file_size,
210
2.05k
         NULL );
211
212
2.05k
        libfsext_file_entry_get_number_of_extents(
213
2.05k
         sub_file_entry,
214
2.05k
         &number_of_extents,
215
2.05k
         NULL );
216
2.05k
      }
217
2.58k
      libfsext_file_entry_free(
218
2.58k
       &sub_file_entry,
219
2.58k
       NULL );
220
2.58k
    }
221
3.62k
on_error_libfsext_root_directory:
222
3.62k
    libfsext_file_entry_free(
223
3.62k
     &root_directory,
224
3.62k
     NULL );
225
3.62k
  }
226
5.37k
  libfsext_volume_close(
227
5.37k
   volume,
228
5.37k
   NULL );
229
230
7.11k
on_error_libfsext_volume:
231
7.11k
  libfsext_volume_free(
232
7.11k
   &volume,
233
7.11k
   NULL );
234
235
7.11k
on_error_libbfio:
236
7.11k
  libbfio_handle_free(
237
7.11k
   &file_io_handle,
238
7.11k
   NULL );
239
240
7.11k
  return( 0 );
241
7.11k
}
242
243
} /* extern "C" */
244