From 3690d5f53211f04684cccc64fd3d911ac75e897c Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Sun, 9 Oct 2022 12:06:25 +0200 Subject: [PATCH] fuzzing: Simplify proto fuzzer. --- tests/fuzz/crypt2_load_proto_fuzz.cc | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/fuzz/crypt2_load_proto_fuzz.cc b/tests/fuzz/crypt2_load_proto_fuzz.cc index d6adc2ea..598e88d3 100644 --- a/tests/fuzz/crypt2_load_proto_fuzz.cc +++ b/tests/fuzz/crypt2_load_proto_fuzz.cc @@ -37,32 +37,20 @@ extern "C" { } DEFINE_PROTO_FUZZER(const LUKS2_proto::LUKS2_both_headers &headers) { - struct crypt_device *cd; - int r = 0; - + struct crypt_device *cd = NULL; char name[] = "/tmp/test-proto-fuzz.XXXXXX"; int fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC); + if (fd < 0) err(EXIT_FAILURE, "mkostemp() failed"); LUKS2_proto::LUKS2ProtoConverter converter; converter.convert(headers, fd); - r = crypt_init(&cd, name); - if (r < 0 ) { - r = 0; - goto out; - } - - r = crypt_load(cd, CRYPT_LUKS2, NULL); + if (crypt_init(&cd, name) == 0) + (void)crypt_load(cd, CRYPT_LUKS2, NULL); crypt_free(cd); - if (r < 0) { - r = 0; - goto out; - } -out: - if (fd >= 0) - close(fd); + close(fd); unlink(name); }