mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-06 00:10:04 +01:00
Introduce crypt_strcmp function (allows NULL).
This commit is contained in:
@@ -255,6 +255,7 @@ int crypt_serialize_lock(struct crypt_device *cd);
|
||||
void crypt_serialize_unlock(struct crypt_device *cd);
|
||||
|
||||
bool crypt_string_in(const char *str, char **list, size_t list_size);
|
||||
int crypt_strcmp(const char *a, const char *b);
|
||||
static inline void *crypt_zalloc(size_t size) { return calloc(1, size); }
|
||||
|
||||
#endif /* INTERNAL_H */
|
||||
|
||||
18
lib/setup.c
18
lib/setup.c
@@ -2274,16 +2274,6 @@ static int _compare_volume_keys(struct volume_key *svk, unsigned skeyring_only,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* compare two strings (allows NULL) */
|
||||
static int _strcmp_null(const char *a, const char *b)
|
||||
{
|
||||
if (!a && !b)
|
||||
return 0;
|
||||
else if (!a || !b)
|
||||
return 1;
|
||||
return strcmp(a, b);
|
||||
}
|
||||
|
||||
static int _compare_device_types(struct crypt_device *cd,
|
||||
const struct crypt_dm_active_device *src,
|
||||
const struct crypt_dm_active_device *tgt)
|
||||
@@ -2337,7 +2327,7 @@ static int _compare_crypt_devices(struct crypt_device *cd,
|
||||
log_dbg(cd, "Cipher specs do not match.");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (_strcmp_null(src->u.crypt.integrity, tgt->u.crypt.integrity)) {
|
||||
if (crypt_strcmp(src->u.crypt.integrity, tgt->u.crypt.integrity)) {
|
||||
log_dbg(cd, "Integrity parameters do not match.");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -2380,9 +2370,9 @@ static int _compare_integrity_devices(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (_strcmp_null(src->u.integrity.integrity, tgt->u.integrity.integrity) ||
|
||||
_strcmp_null(src->u.integrity.journal_integrity, tgt->u.integrity.journal_integrity) ||
|
||||
_strcmp_null(src->u.integrity.journal_crypt, tgt->u.integrity.journal_crypt)) {
|
||||
if (crypt_strcmp(src->u.integrity.integrity, tgt->u.integrity.integrity) ||
|
||||
crypt_strcmp(src->u.integrity.journal_integrity, tgt->u.integrity.journal_integrity) ||
|
||||
crypt_strcmp(src->u.integrity.journal_crypt, tgt->u.integrity.journal_crypt)) {
|
||||
log_dbg(cd, "Journal parameters do not match.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
10
lib/utils.c
10
lib/utils.c
@@ -334,3 +334,13 @@ bool crypt_string_in(const char *str, char **list, size_t list_size)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* compare two strings (allows NULL values) */
|
||||
int crypt_strcmp(const char *a, const char *b)
|
||||
{
|
||||
if (!a && !b)
|
||||
return 0;
|
||||
else if (!a || !b)
|
||||
return 1;
|
||||
return strcmp(a, b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user