Coverage Report

Created: 2026-07-24 06:26

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