Coverage Report

Created: 2025-06-13 07:21

/src/libregf/ossfuzz/value_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libregf value type
3
 *
4
 * Copyright (C) 2009-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_libregf.h"
31
32
#if !defined( LIBREGF_HAVE_BFIO )
33
34
/* Opens a file using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBREGF_EXTERN \
38
int libregf_file_open_file_io_handle(
39
     libregf_file_t *file,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libregf_error_t **error );
43
44
#endif /* !defined( LIBREGF_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
1.81k
{
50
1.81k
  libbfio_handle_t *file_io_handle = NULL;
51
1.81k
  libregf_file_t *file             = NULL;
52
1.81k
  libregf_key_t *root_key          = NULL;
53
1.81k
  libregf_key_t *sub_key           = NULL;
54
1.81k
  libregf_value_t *value           = NULL;
55
1.81k
  uint32_t value_type              = 0;
56
1.81k
  int number_of_sub_keys           = 0;
57
1.81k
  int number_of_values             = 0;
58
59
1.81k
  if( libbfio_memory_range_initialize(
60
1.81k
       &file_io_handle,
61
1.81k
       NULL ) != 1 )
62
0
  {
63
0
    return( 0 );
64
0
  }
65
1.81k
  if( libbfio_memory_range_set(
66
1.81k
       file_io_handle,
67
1.81k
       (uint8_t *) data,
68
1.81k
       size,
69
1.81k
       NULL ) != 1 )
70
0
  {
71
0
    goto on_error_libbfio;
72
0
  }
73
1.81k
  if( libregf_file_initialize(
74
1.81k
       &file,
75
1.81k
       NULL ) != 1 )
76
0
  {
77
0
    goto on_error_libbfio;
78
0
  }
79
1.81k
  if( libregf_file_open_file_io_handle(
80
1.81k
       file,
81
1.81k
       file_io_handle,
82
1.81k
       LIBREGF_OPEN_READ,
83
1.81k
       NULL ) != 1 )
84
401
  {
85
401
    goto on_error_libregf_file;
86
401
  }
87
1.41k
  if( libregf_file_get_root_key(
88
1.41k
       file,
89
1.41k
       &root_key,
90
1.41k
       NULL ) == 1 )
91
472
  {
92
472
    if( libregf_key_get_number_of_sub_keys(
93
472
         root_key,
94
472
         &number_of_sub_keys,
95
472
         NULL ) != 1 )
96
0
    {
97
0
      goto on_error_libregf_root_key;
98
0
    }
99
472
    if( number_of_sub_keys > 0 )
100
450
    {
101
450
      if( libregf_key_get_sub_key(
102
450
           root_key,
103
450
           0,
104
450
           &sub_key,
105
450
           NULL ) != 1 )
106
42
      {
107
42
        goto on_error_libregf_root_key;
108
42
      }
109
408
      if( libregf_key_get_number_of_values(
110
408
           sub_key,
111
408
           &number_of_values,
112
408
           NULL ) != 1 )
113
0
      {
114
0
        goto on_error_libregf_sub_key;
115
0
      }
116
408
      if( number_of_sub_keys > 0 )
117
408
      {
118
408
        if( libregf_key_get_value(
119
408
             root_key,
120
408
             0,
121
408
             &value,
122
408
             NULL ) != 1 )
123
169
        {
124
169
          goto on_error_libregf_sub_key;
125
169
        }
126
239
        libregf_value_get_value_type(
127
239
         value,
128
239
         &value_type,
129
239
         NULL );
130
131
239
        libregf_value_free(
132
239
         &value,
133
239
         NULL );
134
239
      }
135
408
on_error_libregf_sub_key:
136
408
      libregf_key_free(
137
408
       &sub_key,
138
408
       NULL );
139
408
    }
140
472
on_error_libregf_root_key:
141
472
    libregf_key_free(
142
472
     &root_key,
143
472
     NULL );
144
472
  }
145
1.41k
  libregf_file_close(
146
1.41k
   file,
147
1.41k
   NULL );
148
149
1.81k
on_error_libregf_file:
150
1.81k
  libregf_file_free(
151
1.81k
   &file,
152
1.81k
   NULL );
153
154
1.81k
on_error_libbfio:
155
1.81k
  libbfio_handle_free(
156
1.81k
   &file_io_handle,
157
1.81k
   NULL );
158
159
1.81k
  return( 0 );
160
1.81k
}
161
162
} /* extern "C" */
163