Replace json_bool with stdbool.

This is some relict from old code, just use bool, we already
require it elsewhere.
This commit is contained in:
Milan Broz
2022-06-16 14:28:04 +02:00
parent 18ada2b7de
commit d9b66afe5e
2 changed files with 30 additions and 32 deletions

View File

@@ -72,7 +72,7 @@ void JSON_DBG(struct crypt_device *cd, json_object *jobj, const char *desc);
*/
/* validation helper */
json_bool validate_json_uint32(json_object *jobj);
bool validate_json_uint32(json_object *jobj);
json_object *json_contains(struct crypt_device *cd, json_object *jobj, const char *name,
const char *section, const char *key, json_type type);
json_object *json_contains_string(struct crypt_device *cd, json_object *jobj,

View File

@@ -224,7 +224,7 @@ uint32_t crypt_jobj_get_uint32(json_object *jobj)
}
/* jobj has to be json_type_string and numbered */
static json_bool json_str_to_uint64(json_object *jobj, uint64_t *value)
static bool json_str_to_uint64(json_object *jobj, uint64_t *value)
{
char *endptr;
unsigned long long tmp;
@@ -233,11 +233,11 @@ static json_bool json_str_to_uint64(json_object *jobj, uint64_t *value)
tmp = strtoull(json_object_get_string(jobj), &endptr, 10);
if (*endptr || errno) {
*value = 0;
return 0;
return false;
}
*value = tmp;
return 1;
return true;
}
uint64_t crypt_jobj_get_uint64(json_object *jobj)
@@ -265,16 +265,16 @@ json_object *crypt_jobj_new_uint64(uint64_t value)
/*
* Validate helpers
*/
static json_bool numbered(struct crypt_device *cd, const char *name, const char *key)
static bool numbered(struct crypt_device *cd, const char *name, const char *key)
{
int i;
for (i = 0; key[i]; i++)
if (!isdigit(key[i])) {
log_dbg(cd, "%s \"%s\" is not in numbered form.", name, key);
return 0;
return false;
}
return 1;
return true;
}
json_object *json_contains(struct crypt_device *cd, json_object *jobj, const char *name,
@@ -306,18 +306,17 @@ json_object *json_contains_string(struct crypt_device *cd, json_object *jobj,
return sobj;
}
json_bool validate_json_uint32(json_object *jobj)
bool validate_json_uint32(json_object *jobj)
{
int64_t tmp;
errno = 0;
tmp = json_object_get_int64(jobj);
return (errno || tmp < 0 || tmp > UINT32_MAX) ? 0 : 1;
return (errno || tmp < 0 || tmp > UINT32_MAX) ? false : true;
}
static json_bool validate_keyslots_array(struct crypt_device *cd,
json_object *jarr, json_object *jobj_keys)
static bool validate_keyslots_array(struct crypt_device *cd, json_object *jarr, json_object *jobj_keys)
{
json_object *jobj;
int i = 0, length = (int) json_object_array_length(jarr);
@@ -326,21 +325,20 @@ static json_bool validate_keyslots_array(struct crypt_device *cd,
jobj = json_object_array_get_idx(jarr, i);
if (!json_object_is_type(jobj, json_type_string)) {
log_dbg(cd, "Illegal value type in keyslots array at index %d.", i);
return 0;
return false;
}
if (!json_contains(cd, jobj_keys, "", "Keyslots section",
json_object_get_string(jobj), json_type_object))
return 0;
return false;
i++;
}
return 1;
return true;
}
static json_bool validate_segments_array(struct crypt_device *cd,
json_object *jarr, json_object *jobj_segments)
static bool validate_segments_array(struct crypt_device *cd, json_object *jarr, json_object *jobj_segments)
{
json_object *jobj;
int i = 0, length = (int) json_object_array_length(jarr);
@@ -349,20 +347,20 @@ static json_bool validate_segments_array(struct crypt_device *cd,
jobj = json_object_array_get_idx(jarr, i);
if (!json_object_is_type(jobj, json_type_string)) {
log_dbg(cd, "Illegal value type in segments array at index %d.", i);
return 0;
return false;
}
if (!json_contains(cd, jobj_segments, "", "Segments section",
json_object_get_string(jobj), json_type_object))
return 0;
return false;
i++;
}
return 1;
return true;
}
static json_bool segment_has_digest(const char *segment_name, json_object *jobj_digests)
static bool segment_has_digest(const char *segment_name, json_object *jobj_digests)
{
json_object *jobj_segments;
@@ -370,14 +368,14 @@ static json_bool segment_has_digest(const char *segment_name, json_object *jobj_
UNUSED(key);
json_object_object_get_ex(val, "segments", &jobj_segments);
if (LUKS2_array_jobj(jobj_segments, segment_name))
return 1;
return true;
}
return 0;
return false;
}
static json_bool validate_intervals(struct crypt_device *cd,
static bool validate_intervals(struct crypt_device *cd,
int length, const struct interval *ix,
uint64_t metadata_size, uint64_t keyslots_area_end)
{
@@ -386,23 +384,23 @@ static json_bool validate_intervals(struct crypt_device *cd,
while (i < length) {
if (ix[i].offset < 2 * metadata_size) {
log_dbg(cd, "Illegal area offset: %" PRIu64 ".", ix[i].offset);
return 0;
return false;
}
if (!ix[i].length) {
log_dbg(cd, "Area length must be greater than zero.");
return 0;
return false;
}
if (ix[i].offset > (UINT64_MAX - ix[i].length)) {
log_dbg(cd, "Interval offset+length overflow.");
return 0;
return false;
}
if ((ix[i].offset + ix[i].length) > keyslots_area_end) {
log_dbg(cd, "Area [%" PRIu64 ", %" PRIu64 "] overflows binary keyslots area (ends at offset: %" PRIu64 ").",
ix[i].offset, ix[i].offset + ix[i].length, keyslots_area_end);
return 0;
return false;
}
for (j = 0; j < length; j++) {
@@ -411,21 +409,21 @@ static json_bool validate_intervals(struct crypt_device *cd,
if (ix[j].offset > (UINT64_MAX - ix[j].length)) {
log_dbg(cd, "Interval offset+length overflow.");
return 0;
return false;
}
if ((ix[i].offset >= ix[j].offset) && (ix[i].offset < (ix[j].offset + ix[j].length))) {
log_dbg(cd, "Overlapping areas [%" PRIu64 ",%" PRIu64 "] and [%" PRIu64 ",%" PRIu64 "].",
ix[i].offset, ix[i].offset + ix[i].length,
ix[j].offset, ix[j].offset + ix[j].length);
return 0;
return false;
}
}
i++;
}
return 1;
return true;
}
static int LUKS2_keyslot_validate(struct crypt_device *cd, json_object *hdr_keyslot, const char *key)