Files
cryptsetup/tests/fuzz/crypt2_load_ondisk_fuzz.cc
Milan Broz 661f57def4 Use SPDX license identifiers.
This patch switches code to SPDX one-line license identifiers according to
https://spdx.dev/learn/handling-license-info/
and replacing long license text headers.

I used C++ format on the first line in style
// SPDX-License-Identifier: <id>
except exported libcryptsetup.h, when only C comments are used.

The only additional changes are:
- switch backend utf8.c from LGPL2+ to LGPL2.1+ (as in systemd)
- add some additional formatting lines.
2024-06-03 16:38:15 +00:00

52 lines
1.1 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* cryptsetup LUKS1, FileVault, BitLocker fuzz target
*/
extern "C" {
#define FILESIZE (16777216)
#include "src/cryptsetup.h"
#include <err.h>
#include "luks1/luks.h"
#include "crypto_backend/crypto_backend.h"
#include "FuzzerInterface.h"
void empty_log(int level, const char *msg, void *usrptr) {}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int fd, r;
struct crypt_device *cd = NULL;
char name[] = "/tmp/test-script-fuzz.XXXXXX";
fd = mkostemp(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC);
if (fd == -1)
err(EXIT_FAILURE, "mkostemp() failed");
/* enlarge header */
if (ftruncate(fd, FILESIZE) == -1)
goto out;
if (write_buffer(fd, data, size) != (ssize_t) size)
goto out;
crypt_set_log_callback(NULL, empty_log, NULL);
if (crypt_init(&cd, name) == 0) {
r = crypt_load(cd, CRYPT_LUKS1, NULL);
if (r == 0)
goto out;
r = crypt_load(cd, CRYPT_FVAULT2, NULL);
if (r == 0)
goto out;
(void) crypt_load(cd, CRYPT_BITLK, NULL);
}
out:
crypt_free(cd);
close(fd);
unlink(name);
return 0;
}
}