Coverage Report

Created: 2026-08-31 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsxfs/ossfuzz/extended_attribute_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfsxfs extended_attribute type
3
 *
4
 * Copyright (C) 2020-2026, 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
24.1k
{
50
24.1k
  libbfio_handle_t *file_io_handle                  = NULL;
51
24.1k
  libfsxfs_extended_attribute_t *extended_attribute = NULL;
52
24.1k
  libfsxfs_file_entry_t *file_entry                 = NULL;
53
24.1k
  libfsxfs_volume_t *volume                         = NULL;
54
24.1k
  int number_of_extended_attributes                 = 0;
55
24.1k
  int result                                        = 0;
56
57
24.1k
  if( libbfio_memory_range_initialize(
58
24.1k
       &file_io_handle,
59
24.1k
       NULL ) != 1 )
60
0
  {
61
0
    return( 0 );
62
0
  }
63
24.1k
  if( libbfio_memory_range_set(
64
24.1k
       file_io_handle,
65
24.1k
       (uint8_t *) data,
66
24.1k
       size,
67
24.1k
       NULL ) != 1 )
68
0
  {
69
0
    goto on_error_libbfio;
70
0
  }
71
24.1k
  if( libfsxfs_volume_initialize(
72
24.1k
       &volume,
73
24.1k
       NULL ) != 1 )
74
0
  {
75
0
    goto on_error_libbfio;
76
0
  }
77
24.1k
  if( libfsxfs_volume_open_file_io_handle(
78
24.1k
       volume,
79
24.1k
       file_io_handle,
80
24.1k
       LIBFSXFS_OPEN_READ,
81
24.1k
       NULL ) != 1 )
82
12.6k
  {
83
12.6k
    goto on_error_libfsxfs_volume;
84
12.6k
  }
85
11.5k
  result = libfsxfs_volume_get_file_entry_by_utf8_path(
86
11.5k
            volume,
87
11.5k
            (uint8_t *) "/a_directory/a_file",
88
11.5k
            19,
89
11.5k
            &file_entry,
90
11.5k
            NULL );
91
92
11.5k
  if( result == 1 )
93
3.15k
  {
94
3.15k
    if( libfsxfs_file_entry_get_number_of_extended_attributes(
95
3.15k
         file_entry,
96
3.15k
         &number_of_extended_attributes,
97
3.15k
         NULL ) != 1 )
98
1.90k
    {
99
1.90k
      goto on_error_libfsxfs_file_entry;
100
1.90k
    }
101
1.24k
    if( number_of_extended_attributes > 0 )
102
808
    {
103
808
      if( libfsxfs_file_entry_get_extended_attribute_by_index(
104
808
           file_entry,
105
808
           0,
106
808
           &extended_attribute,
107
808
           NULL ) != 1 )
108
223
      {
109
223
        goto on_error_libfsxfs_file_entry;
110
223
      }
111
585
      libfsxfs_extended_attribute_free(
112
585
       &extended_attribute,
113
585
       NULL );
114
585
    }
115
3.15k
on_error_libfsxfs_file_entry:
116
3.15k
    libfsxfs_file_entry_free(
117
3.15k
     &file_entry,
118
3.15k
     NULL );
119
3.15k
  }
120
11.5k
  libfsxfs_volume_close(
121
11.5k
   volume,
122
11.5k
   NULL );
123
124
24.1k
on_error_libfsxfs_volume:
125
24.1k
  libfsxfs_volume_free(
126
24.1k
   &volume,
127
24.1k
   NULL );
128
129
24.1k
on_error_libbfio:
130
24.1k
  libbfio_handle_free(
131
24.1k
   &file_io_handle,
132
24.1k
   NULL );
133
134
24.1k
  return( 0 );
135
24.1k
}
136
137
} /* extern "C" */
138