Fix some clang++ warnings.

This commit is contained in:
Milan Broz
2022-09-30 09:13:19 +02:00
parent e1a84607cc
commit a3f248df9b
7 changed files with 15 additions and 22 deletions

View File

@@ -38,7 +38,9 @@ extern "C" {
#include <libcryptsetup.h>
#include <src/cryptsetup.h>
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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -33,13 +33,12 @@ extern "C" {
#include <err.h>
}
#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();

View File

@@ -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;

View File

@@ -31,7 +31,7 @@ extern "C" {
#include <err.h>
}
#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();

View File

@@ -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;