mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
fuzzing: Simplify plain JSON fuzzer.
This commit is contained in:
@@ -37,32 +37,20 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) {
|
DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) {
|
||||||
struct crypt_device *cd;
|
struct crypt_device *cd = NULL;
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
||||||
int fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
|
int fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
err(EXIT_FAILURE, "mkostemp() failed");
|
err(EXIT_FAILURE, "mkostemp() failed");
|
||||||
|
|
||||||
json_proto::LUKS2ProtoConverter converter;
|
json_proto::LUKS2ProtoConverter converter;
|
||||||
converter.convert(headers, fd);
|
converter.convert(headers, fd);
|
||||||
|
|
||||||
r = crypt_init(&cd, name);
|
if (crypt_init(&cd, name) == 0)
|
||||||
if (r < 0 ) {
|
(void)crypt_load(cd, CRYPT_LUKS2, NULL);
|
||||||
r = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = crypt_load(cd, CRYPT_LUKS2, NULL);
|
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
if (r < 0) {
|
|
||||||
r = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
close(fd);
|
||||||
if (fd >= 0)
|
|
||||||
close(fd);
|
|
||||||
unlink(name);
|
unlink(name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user