diff --git a/tests/fuzz/crypt2_load_fuzz.cc b/tests/fuzz/crypt2_load_fuzz.cc index f3eea368..0a196553 100644 --- a/tests/fuzz/crypt2_load_fuzz.cc +++ b/tests/fuzz/crypt2_load_fuzz.cc @@ -38,7 +38,9 @@ extern "C" { #include #include -int calculate_checksum(const uint8_t* data, size_t size) { +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +static int calculate_checksum(const uint8_t* data, size_t size) { struct crypt_hash *hd = NULL; struct luks2_hdr_disk *hdr = NULL; int hash_size; @@ -48,7 +50,7 @@ int calculate_checksum(const uint8_t* data, size_t size) { // primary header if (sizeof(struct luks2_hdr_disk) > size) return 0; - hdr = (struct luks2_hdr_disk *) data; + hdr = CONST_CAST(struct luks2_hdr_disk *) data; hdr_size1 = be64_to_cpu(hdr->hdr_size); if (hdr_size1 > size) @@ -56,7 +58,7 @@ int calculate_checksum(const uint8_t* data, size_t size) { memset(&hdr->csum, 0, LUKS2_CHECKSUM_L); if ((r = crypt_hash_init(&hd, "sha256"))) goto out; - if ((r = crypt_hash_write(hd, (char*) data, hdr_size1))) + if ((r = crypt_hash_write(hd, CONST_CAST(char*) data, hdr_size1))) goto out; hash_size = crypt_hash_size("sha256"); if (hash_size <= 0) { @@ -73,7 +75,7 @@ int calculate_checksum(const uint8_t* data, size_t size) { if (hdr_size1 + sizeof(struct luks2_hdr_disk) > size) return 0; - hdr = (struct luks2_hdr_disk *) (data + hdr_size1); + hdr = CONST_CAST(struct luks2_hdr_disk *) (data + hdr_size1); hdr_size2 = be64_to_cpu(hdr->hdr_size); if (hdr_size1 + hdr_size2 > size) @@ -97,7 +99,6 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { int fd; struct crypt_device *cd; int result; - uint8_t *map; int r = 0; char name[] = "/tmp/test-script-fuzz.XXXXXX"; diff --git a/tests/fuzz/crypt2_load_proto_fuzz.cc b/tests/fuzz/crypt2_load_proto_fuzz.cc index e4decde9..11feccf7 100644 --- a/tests/fuzz/crypt2_load_proto_fuzz.cc +++ b/tests/fuzz/crypt2_load_proto_fuzz.cc @@ -36,9 +36,7 @@ extern "C" { } DEFINE_PROTO_FUZZER(const LUKS2_proto::LUKS2_both_headers &headers) { - int result; struct crypt_device *cd; - uint8_t *map; int r = 0; char name[] = "/tmp/test-proto-fuzz.XXXXXX"; diff --git a/tests/fuzz/crypt2_load_proto_plain_json_fuzz.cc b/tests/fuzz/crypt2_load_proto_plain_json_fuzz.cc index ea957115..56f01288 100644 --- a/tests/fuzz/crypt2_load_proto_plain_json_fuzz.cc +++ b/tests/fuzz/crypt2_load_proto_plain_json_fuzz.cc @@ -36,9 +36,7 @@ extern "C" { } DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) { - int result; struct crypt_device *cd; - uint8_t *map; int r = 0; char name[] = "/tmp/test-proto-fuzz.XXXXXX"; diff --git a/tests/fuzz/plain_json_proto_to_luks2_converter.cc b/tests/fuzz/plain_json_proto_to_luks2_converter.cc index 1aa8f3fd..f5c66ca9 100644 --- a/tests/fuzz/plain_json_proto_to_luks2_converter.cc +++ b/tests/fuzz/plain_json_proto_to_luks2_converter.cc @@ -33,13 +33,12 @@ extern "C" { #include } -#define OFFSET_OF(strct, field) (((char*)&((struct strct*)0)->field) - (char*)0) +//#define OFFSET_OF(strct, field) (((char*)&((struct strct*)0)->field) - (char*)0) namespace json_proto { void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_proto, int fd, uint64_t offset, uint64_t seqid, const std::string &json_text) { struct luks2_hdr_disk hdr = {}; - char *json_area = NULL; int r; if (hd) @@ -97,7 +96,7 @@ void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_pr } if (header_proto.use_correct_checksum()) { - if (lseek(fd, offset + OFFSET_OF(luks2_hdr_disk, csum), SEEK_SET) == -1) + if (lseek(fd, offset + offsetof(luks2_hdr_disk, csum), SEEK_SET) == -1) err(EXIT_FAILURE, "lseek failed"); int hash_size = crypt_hash_size("sha256"); @@ -117,7 +116,6 @@ void LUKS2ProtoConverter::set_write_headers_only(bool headers_only) { void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) { uint64_t primary_seqid, secondary_seqid; - const char name_pattern[] = "/tmp/test-proto-fuzz.XXXXXX"; int result; size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size(); diff --git a/tests/fuzz/plain_json_proto_to_luks2_converter.h b/tests/fuzz/plain_json_proto_to_luks2_converter.h index 013fdb71..14c39f43 100644 --- a/tests/fuzz/plain_json_proto_to_luks2_converter.h +++ b/tests/fuzz/plain_json_proto_to_luks2_converter.h @@ -44,7 +44,7 @@ class LUKS2ProtoConverter { void set_write_headers_only(bool headers_only); const uint8_t *get_out_buffer(); - const size_t get_out_size(); + size_t get_out_size(); static const uint64_t KEYSLOTS_SIZE = 3 * 1024 * 1024; static const uint64_t DATA_SIZE = 16 * 1024 * 1024; diff --git a/tests/fuzz/proto_to_luks2_converter.cc b/tests/fuzz/proto_to_luks2_converter.cc index d575ce96..865e25bd 100644 --- a/tests/fuzz/proto_to_luks2_converter.cc +++ b/tests/fuzz/proto_to_luks2_converter.cc @@ -31,7 +31,7 @@ extern "C" { #include } -#define OFFSET_OF(strct, field) (((char*)&((struct strct*)0)->field) - (char*)0) +//#define OFFSET_OF(strct, field) (((char*)&((struct strct*)0)->field) - (char*)0) namespace LUKS2_proto { @@ -246,7 +246,7 @@ void LUKS2ProtoConverter::generate_token(struct json_object *jobj_tokens, const if (!token_desc.keyslots().empty()) { jobj_keyslots = json_object_new_array(); - for (const object_id oid : token_desc.keyslots()) { + for (const object_id& oid : token_desc.keyslots()) { json_object_array_add(jobj_keyslots, json_object_new_string(object_id_to_string(oid).c_str())); } @@ -269,7 +269,7 @@ void LUKS2ProtoConverter::generate_digest(struct json_object *jobj_digests, cons if (!digest_desc.keyslots().empty()) { jobj_keyslots = json_object_new_array(); - for (const object_id oid : digest_desc.keyslots()) { + for (const object_id& oid : digest_desc.keyslots()) { json_object_array_add(jobj_keyslots, json_object_new_string(object_id_to_string(oid).c_str())); } @@ -281,7 +281,7 @@ void LUKS2ProtoConverter::generate_digest(struct json_object *jobj_digests, cons if (!digest_desc.segments().empty()) { jobj_segments = json_object_new_array(); - for (const object_id oid : digest_desc.segments()) { + for (const object_id& oid : digest_desc.segments()) { json_object_array_add(jobj_segments, json_object_new_string(object_id_to_string(oid).c_str())); } @@ -417,7 +417,6 @@ void LUKS2ProtoConverter::create_jobj(const LUKS2_both_headers &headers) { void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_proto, int fd, uint64_t offset, uint64_t seqid) { struct luks2_hdr_disk hdr = {}; - char *json_area = NULL; int r; if (hd) @@ -485,7 +484,7 @@ void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_pr } if (header_proto.use_correct_checksum()) { - if (lseek(fd, offset + OFFSET_OF(luks2_hdr_disk, csum), SEEK_SET) == -1) + if (lseek(fd, offset + offsetof(luks2_hdr_disk, csum), SEEK_SET) == -1) err(EXIT_FAILURE, "lseek failed"); int hash_size = crypt_hash_size("sha256"); @@ -505,7 +504,6 @@ void LUKS2ProtoConverter::set_write_headers_only(bool headers_only) { void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) { uint64_t primary_seqid, secondary_seqid; - const char name_pattern[] = "/tmp/test-proto-fuzz.XXXXXX"; int result; size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size(); diff --git a/tests/fuzz/proto_to_luks2_converter.h b/tests/fuzz/proto_to_luks2_converter.h index 282f13b7..051f675c 100644 --- a/tests/fuzz/proto_to_luks2_converter.h +++ b/tests/fuzz/proto_to_luks2_converter.h @@ -76,7 +76,7 @@ class LUKS2ProtoConverter { void set_write_headers_only(bool headers_only); const uint8_t *get_out_buffer(); - const size_t get_out_size(); + size_t get_out_size(); static const uint64_t KEYSLOTS_SIZE = 3 * 1024 * 1024; static const uint64_t DATA_SIZE = 16 * 1024 * 1024;