Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libluksde/ossfuzz/volume_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libluksde volume type
3
 *
4
 * Copyright (C) 2013-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_libluksde.h"
31
32
#if !defined( LIBLUKSDE_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
LIBLUKSDE_EXTERN \
38
int libluksde_volume_open_file_io_handle(
39
     libluksde_volume_t *volume,
40
     libbfio_handle_t *file_io_handle,
41
     int access_flags,
42
     libluksde_error_t **error );
43
44
#endif /* !defined( LIBLUKSDE_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
     const uint8_t *data,
48
     size_t size )
49
1.42k
{
50
1.42k
  uint8_t buffer[ 512 ];
51
1.42k
  uint8_t uuid[ 16 ];
52
53
1.42k
  libbfio_handle_t *file_io_handle = NULL;
54
1.42k
  libluksde_volume_t *volume       = NULL;
55
1.42k
  off64_t volume_offset            = 0;
56
1.42k
  size64_t volume_size             = 0;
57
1.42k
  int encryption_chaining_mode     = 0;
58
1.42k
  int encryption_method            = 0;
59
1.42k
  int is_locked                    = 0;
60
1.42k
  int read_iterator                = 0;
61
62
1.42k
  if( libbfio_memory_range_initialize(
63
1.42k
       &file_io_handle,
64
1.42k
       NULL ) != 1 )
65
0
  {
66
0
    return( 0 );
67
0
  }
68
1.42k
  if( libbfio_memory_range_set(
69
1.42k
       file_io_handle,
70
1.42k
       (uint8_t *) data,
71
1.42k
       size,
72
1.42k
       NULL ) != 1 )
73
0
  {
74
0
    goto on_error_libbfio;
75
0
  }
76
1.42k
  if( libluksde_volume_initialize(
77
1.42k
       &volume,
78
1.42k
       NULL ) != 1 )
79
0
  {
80
0
    goto on_error_libbfio;
81
0
  }
82
1.42k
  if( libluksde_volume_set_utf8_password(
83
1.42k
       volume,
84
1.42k
       (uint8_t *) "luksde-TEST",
85
1.42k
       11,
86
1.42k
       NULL ) != 1 )
87
0
  {
88
0
    goto on_error_libbfio;
89
0
  }
90
1.42k
  if( libluksde_volume_open_file_io_handle(
91
1.42k
       volume,
92
1.42k
       file_io_handle,
93
1.42k
       LIBLUKSDE_OPEN_READ,
94
1.42k
       NULL ) != 1 )
95
1.37k
  {
96
1.37k
    goto on_error_libluksde;
97
1.37k
  }
98
49
  if( libluksde_volume_get_encryption_method(
99
49
       volume,
100
49
       &encryption_method,
101
49
       &encryption_chaining_mode,
102
49
       NULL ) != 1 )
103
0
  {
104
0
    goto on_error_libluksde;
105
0
  }
106
49
  if( libluksde_volume_get_volume_identifier(
107
49
       volume,
108
49
       uuid,
109
49
       16,
110
49
       NULL ) != 1 )
111
0
  {
112
0
    goto on_error_libluksde;
113
0
  }
114
49
  is_locked = libluksde_volume_is_locked(
115
49
               volume,
116
49
         NULL );
117
118
49
  if( is_locked == -1 )
119
0
  {
120
0
    goto on_error_libluksde;
121
0
  }
122
49
  else if( is_locked == 0 )
123
0
  {
124
0
    if( libluksde_volume_get_size(
125
0
         volume,
126
0
         &volume_size,
127
0
         NULL ) != 1 )
128
0
    {
129
0
      goto on_error_libluksde;
130
0
    }
131
0
    for( read_iterator = 0;
132
0
         read_iterator < 128;
133
0
         read_iterator++ )
134
0
    {
135
0
      if( volume_offset >= volume_size )
136
0
      {
137
0
        break;
138
0
      }
139
0
      if( libluksde_volume_read_buffer_at_offset(
140
0
           volume,
141
0
           buffer,
142
0
           497,
143
0
           volume_offset,
144
0
           NULL ) == -1 )
145
0
      {
146
0
        goto on_error_libluksde;
147
0
      }
148
0
      volume_offset += 497;
149
0
    }
150
0
  }
151
49
  libluksde_volume_close(
152
49
   volume,
153
49
   NULL );
154
155
1.42k
on_error_libluksde:
156
1.42k
  libluksde_volume_free(
157
1.42k
   &volume,
158
1.42k
   NULL );
159
160
1.42k
on_error_libbfio:
161
1.42k
  libbfio_handle_free(
162
1.42k
   &file_io_handle,
163
1.42k
   NULL );
164
165
1.42k
  return( 0 );
166
1.42k
}
167
168
} /* extern "C" */
169