Coverage Report

Created: 2026-01-07 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cryptsetup/tests/fuzz/crypt2_load_ondisk_fuzz.cc
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
 * cryptsetup LUKS1, FileVault, BitLocker fuzz target
4
 */
5
6
extern "C" {
7
1.51k
#define FILESIZE (16777216)
8
#include "src/cryptsetup.h"
9
#include <err.h>
10
#include "luks1/luks.h"
11
#include "crypto_backend/crypto_backend.h"
12
#include "FuzzerInterface.h"
13
14
1.67k
void empty_log(int level, const char *msg, void *usrptr) {}
15
16
1.51k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
17
1.51k
  int fd, r;
18
1.51k
  struct crypt_device *cd = NULL;
19
1.51k
  char name[] = "/tmp/test-script-fuzz.XXXXXX";
20
21
1.51k
  fd = mkostemp(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC);
22
1.51k
  if (fd == -1)
23
0
    err(EXIT_FAILURE, "mkostemp() failed");
24
25
  /* enlarge header */
26
1.51k
  if (ftruncate(fd, FILESIZE) == -1)
27
0
    goto out;
28
29
1.51k
  if (write_buffer(fd, data, size) != (ssize_t) size)
30
0
    goto out;
31
32
1.51k
  crypt_set_log_callback(NULL, empty_log, NULL);
33
34
1.51k
  if (crypt_init(&cd, name) == 0) {
35
1.51k
    r = crypt_load(cd, CRYPT_LUKS1, NULL);
36
1.51k
    if (r == 0)
37
25
      goto out;
38
39
1.48k
    r = crypt_load(cd, CRYPT_FVAULT2, NULL);
40
1.48k
    if (r == 0)
41
0
      goto out;
42
43
1.48k
    (void) crypt_load(cd, CRYPT_BITLK, NULL);
44
1.48k
  }
45
1.51k
out:
46
1.51k
  crypt_free(cd);
47
1.51k
  close(fd);
48
1.51k
  unlink(name);
49
1.51k
  return 0;
50
1.51k
}
51
}