mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-16 21:29:59 +01:00
Fix some clang++ warnings.
This commit is contained in:
@@ -38,7 +38,9 @@ extern "C" {
|
|||||||
#include <libcryptsetup.h>
|
#include <libcryptsetup.h>
|
||||||
#include <src/cryptsetup.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 crypt_hash *hd = NULL;
|
||||||
struct luks2_hdr_disk *hdr = NULL;
|
struct luks2_hdr_disk *hdr = NULL;
|
||||||
int hash_size;
|
int hash_size;
|
||||||
@@ -48,7 +50,7 @@ int calculate_checksum(const uint8_t* data, size_t size) {
|
|||||||
// primary header
|
// primary header
|
||||||
if (sizeof(struct luks2_hdr_disk) > size)
|
if (sizeof(struct luks2_hdr_disk) > size)
|
||||||
return 0;
|
return 0;
|
||||||
hdr = (struct luks2_hdr_disk *) data;
|
hdr = CONST_CAST(struct luks2_hdr_disk *) data;
|
||||||
|
|
||||||
hdr_size1 = be64_to_cpu(hdr->hdr_size);
|
hdr_size1 = be64_to_cpu(hdr->hdr_size);
|
||||||
if (hdr_size1 > 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);
|
memset(&hdr->csum, 0, LUKS2_CHECKSUM_L);
|
||||||
if ((r = crypt_hash_init(&hd, "sha256")))
|
if ((r = crypt_hash_init(&hd, "sha256")))
|
||||||
goto out;
|
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;
|
goto out;
|
||||||
hash_size = crypt_hash_size("sha256");
|
hash_size = crypt_hash_size("sha256");
|
||||||
if (hash_size <= 0) {
|
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)
|
if (hdr_size1 + sizeof(struct luks2_hdr_disk) > size)
|
||||||
return 0;
|
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);
|
hdr_size2 = be64_to_cpu(hdr->hdr_size);
|
||||||
if (hdr_size1 + hdr_size2 > size)
|
if (hdr_size1 + hdr_size2 > size)
|
||||||
@@ -97,7 +99,6 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
int fd;
|
int fd;
|
||||||
struct crypt_device *cd;
|
struct crypt_device *cd;
|
||||||
int result;
|
int result;
|
||||||
uint8_t *map;
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
char name[] = "/tmp/test-script-fuzz.XXXXXX";
|
char name[] = "/tmp/test-script-fuzz.XXXXXX";
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_PROTO_FUZZER(const LUKS2_proto::LUKS2_both_headers &headers) {
|
DEFINE_PROTO_FUZZER(const LUKS2_proto::LUKS2_both_headers &headers) {
|
||||||
int result;
|
|
||||||
struct crypt_device *cd;
|
struct crypt_device *cd;
|
||||||
uint8_t *map;
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) {
|
DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) {
|
||||||
int result;
|
|
||||||
struct crypt_device *cd;
|
struct crypt_device *cd;
|
||||||
uint8_t *map;
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
char name[] = "/tmp/test-proto-fuzz.XXXXXX";
|
||||||
|
|||||||
@@ -33,13 +33,12 @@ extern "C" {
|
|||||||
#include <err.h>
|
#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 {
|
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) {
|
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 = {};
|
struct luks2_hdr_disk hdr = {};
|
||||||
char *json_area = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (hd)
|
if (hd)
|
||||||
@@ -97,7 +96,7 @@ void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (header_proto.use_correct_checksum()) {
|
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");
|
err(EXIT_FAILURE, "lseek failed");
|
||||||
|
|
||||||
int hash_size = crypt_hash_size("sha256");
|
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) {
|
void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) {
|
||||||
uint64_t primary_seqid, secondary_seqid;
|
uint64_t primary_seqid, secondary_seqid;
|
||||||
const char name_pattern[] = "/tmp/test-proto-fuzz.XXXXXX";
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size();
|
size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class LUKS2ProtoConverter {
|
|||||||
void set_write_headers_only(bool headers_only);
|
void set_write_headers_only(bool headers_only);
|
||||||
|
|
||||||
const uint8_t *get_out_buffer();
|
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 KEYSLOTS_SIZE = 3 * 1024 * 1024;
|
||||||
static const uint64_t DATA_SIZE = 16 * 1024 * 1024;
|
static const uint64_t DATA_SIZE = 16 * 1024 * 1024;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ extern "C" {
|
|||||||
#include <err.h>
|
#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 {
|
namespace LUKS2_proto {
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ void LUKS2ProtoConverter::generate_token(struct json_object *jobj_tokens, const
|
|||||||
if (!token_desc.keyslots().empty()) {
|
if (!token_desc.keyslots().empty()) {
|
||||||
jobj_keyslots = json_object_new_array();
|
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_array_add(jobj_keyslots,
|
||||||
json_object_new_string(object_id_to_string(oid).c_str()));
|
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()) {
|
if (!digest_desc.keyslots().empty()) {
|
||||||
jobj_keyslots = json_object_new_array();
|
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_array_add(jobj_keyslots,
|
||||||
json_object_new_string(object_id_to_string(oid).c_str()));
|
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()) {
|
if (!digest_desc.segments().empty()) {
|
||||||
jobj_segments = json_object_new_array();
|
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_array_add(jobj_segments,
|
||||||
json_object_new_string(object_id_to_string(oid).c_str()));
|
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) {
|
void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_proto, int fd, uint64_t offset, uint64_t seqid) {
|
||||||
struct luks2_hdr_disk hdr = {};
|
struct luks2_hdr_disk hdr = {};
|
||||||
char *json_area = NULL;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (hd)
|
if (hd)
|
||||||
@@ -485,7 +484,7 @@ void LUKS2ProtoConverter::emit_luks2_binary_header(const LUKS2_header &header_pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (header_proto.use_correct_checksum()) {
|
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");
|
err(EXIT_FAILURE, "lseek failed");
|
||||||
|
|
||||||
int hash_size = crypt_hash_size("sha256");
|
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) {
|
void LUKS2ProtoConverter::convert(const LUKS2_both_headers &headers, int fd) {
|
||||||
uint64_t primary_seqid, secondary_seqid;
|
uint64_t primary_seqid, secondary_seqid;
|
||||||
const char name_pattern[] = "/tmp/test-proto-fuzz.XXXXXX";
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size();
|
size_t out_size = headers.primary_header().hdr_size() + headers.secondary_header().hdr_size();
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class LUKS2ProtoConverter {
|
|||||||
void set_write_headers_only(bool headers_only);
|
void set_write_headers_only(bool headers_only);
|
||||||
|
|
||||||
const uint8_t *get_out_buffer();
|
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 KEYSLOTS_SIZE = 3 * 1024 * 1024;
|
||||||
static const uint64_t DATA_SIZE = 16 * 1024 * 1024;
|
static const uint64_t DATA_SIZE = 16 * 1024 * 1024;
|
||||||
|
|||||||
Reference in New Issue
Block a user