Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsntfs/ossfuzz/usn_change_journal_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfsntfs USN change journal type
3
 *
4
 * Copyright (C) 2010-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_libfsntfs.h"
31
32
#if !defined( LIBFSNTFS_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
LIBFSNTFS_EXTERN \
38
int libfsntfs_volume_open_file_io_handle(
39
      libfsntfs_volume_t *volume,
40
      libbfio_handle_t *file_io_handle,
41
      int access_flags,
42
      libfsntfs_error_t **error );
43
44
#endif /* !defined( LIBFSNTFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
      const uint8_t *data,
48
      size_t size )
49
5.66k
{
50
5.66k
  uint8_t usn_record[ 512 ];
51
52
5.66k
  libbfio_handle_t *file_io_handle                      = NULL;
53
5.66k
  libfsntfs_usn_change_journal_t *usn_change_journal    = NULL;
54
5.66k
  libfsntfs_volume_t *volume                            = NULL;
55
5.66k
  off64_t journal_offset                                = 0;
56
5.66k
  ssize_t read_count                                    = 0;
57
5.66k
  int read_iterator                                     = 0;
58
5.66k
  int result                                            = 0;
59
60
5.66k
  if( libbfio_memory_range_initialize(
61
5.66k
       &file_io_handle,
62
5.66k
       NULL ) != 1 )
63
0
  {
64
0
    return( 0 );
65
0
  }
66
5.66k
  if( libbfio_memory_range_set(
67
5.66k
       file_io_handle,
68
5.66k
       (uint8_t *) data,
69
5.66k
       size,
70
5.66k
       NULL ) != 1 )
71
0
  {
72
0
    goto on_error_libbfio;
73
0
  }
74
5.66k
  if( libfsntfs_volume_initialize(
75
5.66k
       &volume,
76
5.66k
       NULL ) != 1 )
77
0
  {
78
0
    goto on_error_libbfio;
79
0
  }
80
5.66k
  if( libfsntfs_volume_open_file_io_handle(
81
5.66k
       volume,
82
5.66k
       file_io_handle,
83
5.66k
       LIBFSNTFS_OPEN_READ,
84
5.66k
       NULL ) != 1 )
85
4.32k
  {
86
4.32k
    goto on_error_libfsntfs;
87
4.32k
  }
88
1.34k
  result = libfsntfs_volume_get_usn_change_journal(
89
1.34k
            volume,
90
1.34k
            &usn_change_journal,
91
1.34k
            NULL );
92
93
1.34k
  if( result == -1 )
94
1.19k
  {
95
1.19k
    goto on_error_libfsntfs;
96
1.19k
  }
97
149
  if( result == 1 )
98
0
  {
99
0
    if( libfsntfs_usn_change_journal_get_offset(
100
0
         usn_change_journal,
101
0
         &journal_offset,
102
0
         NULL ) == -1 )
103
0
    {
104
0
      goto on_error_libfsntfs_usn_change_journal;
105
0
    }
106
0
    for( read_iterator = 0;
107
0
         read_iterator < 128;
108
0
         read_iterator++ )
109
0
    {
110
0
      read_count = libfsntfs_usn_change_journal_read_usn_record(
111
0
                         usn_change_journal,
112
0
                         usn_record,
113
0
                         512,
114
0
                         NULL );
115
116
0
      if( read_count == -1 )
117
0
      {
118
0
        goto on_error_libfsntfs_usn_change_journal;
119
0
      }
120
0
      if( read_count == 0 )
121
0
      {
122
0
        break;
123
0
      }
124
0
    }
125
0
on_error_libfsntfs_usn_change_journal:
126
0
    libfsntfs_usn_change_journal_free(
127
0
     &usn_change_journal,
128
0
     NULL );
129
0
  }
130
149
  libfsntfs_volume_close(
131
149
   volume,
132
149
   NULL );
133
134
5.66k
on_error_libfsntfs:
135
5.66k
  libfsntfs_volume_free(
136
5.66k
   &volume,
137
5.66k
   NULL );
138
139
5.66k
on_error_libbfio:
140
5.66k
  libbfio_handle_free(
141
5.66k
   &file_io_handle,
142
5.66k
   NULL );
143
144
5.66k
  return( 0 );
145
5.66k
}
146
147
} /* extern "C" */