Coverage Report

Created: 2024-02-25 07:20

/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-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_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
6.56k
{
50
6.56k
  uint8_t string_value[ 64 ];
51
52
6.56k
  libbfio_handle_t *file_io_handle      = NULL;
53
6.56k
  libfsext_file_entry_t *root_directory = NULL;
54
6.56k
  libfsext_file_entry_t *sub_file_entry = NULL;
55
6.56k
  libfsext_volume_t *volume             = NULL;
56
6.56k
  size64_t file_size                    = 0;
57
6.56k
  size_t string_size                    = 0;
58
6.56k
  off64_t file_offset                   = 0;
59
6.56k
  int64_t posix_time_64bit              = 0;
60
6.56k
  uint32_t value_32bit                  = 0;
61
6.56k
  int32_t posix_time_32bit              = 0;
62
6.56k
  uint16_t value_16bit                  = 0;
63
6.56k
  uint8_t major_device_number           = 0;
64
6.56k
  uint8_t minor_device_number           = 0;
65
6.56k
  int number_of_extents                 = 0;
66
6.56k
  int number_of_sub_file_entries        = 0;
67
6.56k
  int result                            = 0;
68
69
6.56k
  if( libbfio_memory_range_initialize(
70
6.56k
       &file_io_handle,
71
6.56k
       NULL ) != 1 )
72
0
  {
73
0
    return( 0 );
74
0
  }
75
6.56k
  if( libbfio_memory_range_set(
76
6.56k
       file_io_handle,
77
6.56k
       (uint8_t *) data,
78
6.56k
       size,
79
6.56k
       NULL ) != 1 )
80
0
  {
81
0
    goto on_error_libbfio;
82
0
  }
83
6.56k
  if( libfsext_volume_initialize(
84
6.56k
       &volume,
85
6.56k
       NULL ) != 1 )
86
0
  {
87
0
    goto on_error_libbfio;
88
0
  }
89
6.56k
  if( libfsext_volume_open_file_io_handle(
90
6.56k
       volume,
91
6.56k
       file_io_handle,
92
6.56k
       LIBFSEXT_OPEN_READ,
93
6.56k
       NULL ) != 1 )
94
1.62k
  {
95
1.62k
    goto on_error_libfsext_volume;
96
1.62k
  }
97
4.93k
  if( libfsext_volume_get_root_directory(
98
4.93k
       volume,
99
4.93k
       &root_directory,
100
4.93k
       NULL ) == 1 )
101
3.31k
  {
102
3.31k
    if( libfsext_file_entry_get_number_of_sub_file_entries(
103
3.31k
         root_directory,
104
3.31k
         &number_of_sub_file_entries,
105
3.31k
         NULL ) != 1 )
106
674
    {
107
674
      goto on_error_libfsext_root_directory;
108
674
    }
109
2.64k
    if( number_of_sub_file_entries > 0 )
110
2.36k
    {
111
2.36k
      result = libfsext_file_entry_get_sub_file_entry_by_index(
112
2.36k
                root_directory,
113
2.36k
                0,
114
2.36k
                &sub_file_entry,
115
2.36k
                NULL );
116
117
2.36k
      if( result != -1 )
118
1.91k
      {
119
1.91k
        libfsext_file_entry_get_inode_number(
120
1.91k
         sub_file_entry,
121
1.91k
         &value_32bit,
122
1.91k
         NULL );
123
124
1.91k
        libfsext_file_entry_get_creation_time(
125
1.91k
         sub_file_entry,
126
1.91k
         &posix_time_64bit,
127
1.91k
         NULL );
128
129
1.91k
        libfsext_file_entry_get_modification_time(
130
1.91k
         sub_file_entry,
131
1.91k
         &posix_time_64bit,
132
1.91k
         NULL );
133
134
1.91k
        libfsext_file_entry_get_access_time(
135
1.91k
         sub_file_entry,
136
1.91k
         &posix_time_64bit,
137
1.91k
         NULL );
138
139
1.91k
        libfsext_file_entry_get_inode_change_time(
140
1.91k
         sub_file_entry,
141
1.91k
         &posix_time_64bit,
142
1.91k
         NULL );
143
144
1.91k
        libfsext_file_entry_get_deletion_time(
145
1.91k
         sub_file_entry,
146
1.91k
         &posix_time_32bit,
147
1.91k
         NULL );
148
149
1.91k
        libfsext_file_entry_get_file_mode(
150
1.91k
         sub_file_entry,
151
1.91k
         &value_16bit,
152
1.91k
         NULL );
153
154
1.91k
        libfsext_file_entry_get_number_of_links(
155
1.91k
         sub_file_entry,
156
1.91k
         &value_16bit,
157
1.91k
         NULL );
158
159
1.91k
        libfsext_file_entry_get_owner_identifier(
160
1.91k
         sub_file_entry,
161
1.91k
         &value_32bit,
162
1.91k
         NULL );
163
164
1.91k
        libfsext_file_entry_get_group_identifier(
165
1.91k
         sub_file_entry,
166
1.91k
         &value_32bit,
167
1.91k
         NULL );
168
169
1.91k
        libfsext_file_entry_get_device_identifier(
170
1.91k
         sub_file_entry,
171
1.91k
         &value_32bit,
172
1.91k
         NULL );
173
174
1.91k
        libfsext_file_entry_get_device_number(
175
1.91k
         sub_file_entry,
176
1.91k
         &major_device_number,
177
1.91k
         &minor_device_number,
178
1.91k
         NULL );
179
180
1.91k
        libfsext_file_entry_get_utf8_name_size(
181
1.91k
         sub_file_entry,
182
1.91k
         &string_size,
183
1.91k
         NULL );
184
185
1.91k
        libfsext_file_entry_get_utf8_name(
186
1.91k
         sub_file_entry,
187
1.91k
         string_value,
188
1.91k
         64,
189
1.91k
         NULL );
190
191
1.91k
        libfsext_file_entry_get_utf8_symbolic_link_target_size(
192
1.91k
         sub_file_entry,
193
1.91k
         &string_size,
194
1.91k
         NULL );
195
196
1.91k
        libfsext_file_entry_get_utf8_symbolic_link_target(
197
1.91k
         sub_file_entry,
198
1.91k
         string_value,
199
1.91k
         64,
200
1.91k
         NULL );
201
202
1.91k
        libfsext_file_entry_get_offset(
203
1.91k
         sub_file_entry,
204
1.91k
         &file_offset,
205
1.91k
         NULL );
206
207
1.91k
        libfsext_file_entry_get_size(
208
1.91k
         sub_file_entry,
209
1.91k
         &file_size,
210
1.91k
         NULL );
211
212
1.91k
        libfsext_file_entry_get_number_of_extents(
213
1.91k
         sub_file_entry,
214
1.91k
         &number_of_extents,
215
1.91k
         NULL );
216
1.91k
      }
217
2.36k
      libfsext_file_entry_free(
218
2.36k
       &sub_file_entry,
219
2.36k
       NULL );
220
2.36k
    }
221
3.31k
on_error_libfsext_root_directory:
222
3.31k
    libfsext_file_entry_free(
223
3.31k
     &root_directory,
224
3.31k
     NULL );
225
3.31k
  }
226
4.93k
  libfsext_volume_close(
227
4.93k
   volume,
228
4.93k
   NULL );
229
230
6.56k
on_error_libfsext_volume:
231
6.56k
  libfsext_volume_free(
232
6.56k
   &volume,
233
6.56k
   NULL );
234
235
6.56k
on_error_libbfio:
236
6.56k
  libbfio_handle_free(
237
6.56k
   &file_io_handle,
238
6.56k
   NULL );
239
240
6.56k
  return( 0 );
241
6.56k
}
242
243
} /* extern "C" */
244