--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/* Disable this transformation for iovec-util.h and the unit test */
+@ depends on !(file in "src/basic/iovec-util.h")
+ && !(file in "src/test/test-iovec-util.c") @
+expression a, b;
+@@
+(
+- iovec_memcmp(a, b) == 0
++ iovec_equal(a, b)
+|
+- iovec_memcmp(a, b) != 0
++ !iovec_equal(a, b)
+|
+- ASSERT_EQ(iovec_memcmp(a, b), 0)
++ ASSERT_TRUE(iovec_equal(a, b))
+|
+- ASSERT_NE(iovec_memcmp(a, b), 0)
++ ASSERT_FALSE(iovec_equal(a, b))
+)
for (const MountEntry *m = needle + 1; m < ml->mounts + ml->n_mounts; m++) {
if (m->mode != MOUNT_EXTENSION_IMAGE)
continue;
- if (iovec_memcmp(&m->verity.root_hash, &needle->verity.root_hash) == 0)
+ if (iovec_equal(&m->verity.root_hash, &needle->verity.root_hash))
return true;
}
if (r < 0)
return log_error_errno(r, "Invalid hex data in 'tpm2-policy-hash' field item : %m");
- if (iovec_memcmp(policy_hash + j, &thash) != 0) {
+ if (!iovec_equal(policy_hash + j, &thash)) {
match = false;
break;
}
if (r < 0)
return log_error_errno(r, "Invalid hex data in 'tpm2-policy-hash' field: %m");
- if (iovec_memcmp(policy_hash + 0, &thash) == 0)
+ if (iovec_equal(policy_hash + 0, &thash))
return keyslot; /* Found entry with same hash. */
}
}
if (r < 0)
return log_error_errno(r, "Failed to unseal secret using TPM2: %m");
- if (iovec_memcmp(&secret, &secret2) != 0)
+ if (!iovec_equal(&secret, &secret2))
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "TPM2 seal/unseal verification failed.");
}
}
if (iovec_is_set(&j->expected_checksum) &&
- iovec_memcmp(&j->checksum, &j->expected_checksum) != 0) {
+ !iovec_equal(&j->checksum, &j->expected_checksum)) {
r = log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Checksum of downloaded resource does not match expected checksum, yikes.");
goto finish;
}
return r;
if (!iovec_is_set(&i->config) ||
- iovec_memcmp(&i->config, &IOVEC_MAKE_STRING("{}")) == 0)
+ iovec_equal(&i->config, &IOVEC_MAKE_STRING("{}")))
log_info("Image has no configuration, not saving.");
else {
r = oci_pull_save_nspawn_settings(i);
/* ret_root_hash_sig= */ NULL);
if (r < 0)
return r;
- if (iovec_memcmp(&verity->root_hash, &root_hash) != 0) {
+ if (!iovec_equal(&verity->root_hash, &root_hash)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *found = NULL, *expected = NULL;
r = sym_crypt_volume_key_get(cd, CRYPT_ANY_SLOT, root_hash_existing.iov_base, &root_hash_existing.iov_len, NULL, 0);
if (r < 0)
return log_debug_errno(r, "Error opening verity device, crypt_volume_key_get failed: %m");
- if (iovec_memcmp(&verity->root_hash, &root_hash_existing) != 0)
+ if (!iovec_equal(&verity->root_hash, &root_hash_existing))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Error opening verity device, it already exists but root hashes are different.");
/* Ensure that, if signatures are supported, we only reuse the device if the previous mount used the
/* Check if specified root hash matches if it is specified */
if (iovec_is_set(&verity->root_hash) &&
- iovec_memcmp(&verity->root_hash, &root_hash) != 0) {
+ !iovec_equal(&verity->root_hash, &root_hash)) {
_cleanup_free_ char *a = NULL, *b = NULL;
a = hexmem(root_hash.iov_base, root_hash.iov_len);
if (r < 0) {
if (r != -ENOENT)
return log_error_errno(r, "Failed to read '%s' file: %m", joined);
- } else if (iovec_memcmp(&existing, credential) == 0) {
+ } else if (iovec_equal(&existing, credential)) {
log_debug("Anchor secret file '%s' already matches expectations, not updating.", joined);
return 0;
} else
continue;
}
- if ((!srk || iovec_memcmp(srk, &loaded_policy.srk_handle) == 0) &&
- (!nv || iovec_memcmp(nv, &loaded_policy.nv_handle) == 0)) {
+ if ((!srk || iovec_equal(srk, &loaded_policy.srk_handle)) &&
+ (!nv || iovec_equal(nv, &loaded_policy.nv_handle))) {
*ret = TAKE_STRUCT(loaded_policy);
return 1;
}
/* Even if we ignore if people have non-empty files for this file, let's nonetheless warn about it,
* so that people fix it. After all we want to retain liberty to maybe one day place some useful data
* inside it */
- if (iovec_memcmp(&IOVEC_MAKE(expected_hash, sizeof(expected_hash)), hash) != 0)
+ if (!iovec_equal(&IOVEC_MAKE(expected_hash, sizeof(expected_hash)), hash))
log_warning("Hash of best before marker file '%s' has unexpected value, proceeding anyway.", fn);
usec_t best_before;
&decrypted);
ASSERT_OK(r);
- ASSERT_EQ(iovec_memcmp(&plaintext, &decrypted), 0);
+ ASSERT_TRUE(iovec_equal(&plaintext, &decrypted));
}
static bool try_tpm2(void) {
_cleanup_(iovec_done) struct iovec ra = {};
ASSERT_OK(read_full_file("/tmp/wdfa", (char**) &ra.iov_base, &ra.iov_len));
- ASSERT_EQ(iovec_memcmp(&a, &ra), 0);
+ ASSERT_TRUE(iovec_equal(&a, &ra));
ASSERT_OK_ERRNO(unlink("/tmp/wdfa"));
ASSERT_OK(write_data_file_atomic_at(XAT_FDROOT, "tmp/wdfa", &a, /* flags= */ 0));
iovec_done(&ra);
ASSERT_OK(read_full_file("/tmp/wdfa", (char**) &ra.iov_base, &ra.iov_len));
- ASSERT_EQ(iovec_memcmp(&a, &ra), 0);
+ ASSERT_TRUE(iovec_equal(&a, &ra));
ASSERT_OK_ERRNO(unlink("/tmp/wdfa"));
ASSERT_ERROR(write_data_file_atomic_at(AT_FDCWD, NULL, &a, /* flags= */ 0), EINVAL);
ASSERT_OK(write_data_file_atomic_at(AT_FDCWD, "wdfa", &a, /* flags= */ 0));
iovec_done(&ra);
ASSERT_OK(read_full_file("/tmp/wdfa", (char**) &ra.iov_base, &ra.iov_len));
- ASSERT_EQ(iovec_memcmp(&a, &ra), 0);
+ ASSERT_TRUE(iovec_equal(&a, &ra));
ASSERT_OK_ERRNO(unlink("/tmp/wdfa"));
ASSERT_OK(write_data_file_atomic_at(XAT_FDROOT, "tmp/wdfa", &a, /* flags= */ 0));
iovec_done(&ra);
ASSERT_OK(read_full_file("/tmp/wdfa", (char**) &ra.iov_base, &ra.iov_len));
- ASSERT_EQ(iovec_memcmp(&a, &ra), 0);
+ ASSERT_TRUE(iovec_equal(&a, &ra));
ASSERT_OK_ERRNO(unlink("/tmp/wdfa"));
ASSERT_OK_ERRNO(chdir(cwd));
ASSERT_OK(write_data_file_atomic_at(XAT_FDROOT, "tmp/zzz/wdfa", &a, WRITE_DATA_FILE_MKDIR_0755));
iovec_done(&ra);
ASSERT_OK(read_full_file("/tmp/zzz/wdfa", (char**) &ra.iov_base, &ra.iov_len));
- ASSERT_EQ(iovec_memcmp(&a, &ra), 0);
+ ASSERT_TRUE(iovec_equal(&a, &ra));
ASSERT_OK_ERRNO(unlink("/tmp/zzz/wdfa"));
ASSERT_ERROR(write_data_file_atomic_at(AT_FDCWD, "/tmp/zzz", &a, /* flags= */ 0), EEXIST);
ASSERT_OK(iovw_put_iov(&iovw, &IOVEC_MAKE_STRING("bbb")));
ASSERT_OK(iovw_put_iov(&iovw, &IOVEC_MAKE_STRING("ccc")));
ASSERT_EQ(iovw.count, 3U);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa")), 0);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb")), 0);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc")), 0);
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa")));
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb")));
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc")));
}
TEST(iovw_put_iovw) {
ASSERT_OK(iovw_put_iovw(&target, &source));
ASSERT_EQ(target.count, 6U);
- ASSERT_EQ(iovec_memcmp(&target.iovec[0], &IOVEC_MAKE_STRING("xxx")), 0);
- ASSERT_EQ(iovec_memcmp(&target.iovec[1], &IOVEC_MAKE_STRING("yyy")), 0);
- ASSERT_EQ(iovec_memcmp(&target.iovec[2], &IOVEC_MAKE_STRING("zzz")), 0);
- ASSERT_EQ(iovec_memcmp(&target.iovec[3], &IOVEC_MAKE_STRING("aaa")), 0);
- ASSERT_EQ(iovec_memcmp(&target.iovec[4], &IOVEC_MAKE_STRING("bbb")), 0);
- ASSERT_EQ(iovec_memcmp(&target.iovec[5], &IOVEC_MAKE_STRING("ccc")), 0);
+ ASSERT_TRUE(iovec_equal(&target.iovec[0], &IOVEC_MAKE_STRING("xxx")));
+ ASSERT_TRUE(iovec_equal(&target.iovec[1], &IOVEC_MAKE_STRING("yyy")));
+ ASSERT_TRUE(iovec_equal(&target.iovec[2], &IOVEC_MAKE_STRING("zzz")));
+ ASSERT_TRUE(iovec_equal(&target.iovec[3], &IOVEC_MAKE_STRING("aaa")));
+ ASSERT_TRUE(iovec_equal(&target.iovec[4], &IOVEC_MAKE_STRING("bbb")));
+ ASSERT_TRUE(iovec_equal(&target.iovec[5], &IOVEC_MAKE_STRING("ccc")));
/* iovw_put_iovw() does not copy data, hence the pointers must be equal */
ASSERT_PTR_EQ(target.iovec[3].iov_base, source.iovec[0].iov_base);
/* Source is unchanged */
ASSERT_EQ(source.count, 3U);
- ASSERT_EQ(iovec_memcmp(&source.iovec[0], &IOVEC_MAKE_STRING("aaa")), 0);
- ASSERT_EQ(iovec_memcmp(&source.iovec[1], &IOVEC_MAKE_STRING("bbb")), 0);
- ASSERT_EQ(iovec_memcmp(&source.iovec[2], &IOVEC_MAKE_STRING("ccc")), 0);
+ ASSERT_TRUE(iovec_equal(&source.iovec[0], &IOVEC_MAKE_STRING("aaa")));
+ ASSERT_TRUE(iovec_equal(&source.iovec[1], &IOVEC_MAKE_STRING("bbb")));
+ ASSERT_TRUE(iovec_equal(&source.iovec[2], &IOVEC_MAKE_STRING("ccc")));
/* Cannot pass the same objects */
ASSERT_ERROR(iovw_put_iovw(&target, &target), EINVAL);
ASSERT_OK(iovw_extend_iov(&iovw, &IOVEC_MAKE_STRING("bbb")));
ASSERT_OK(iovw_extend_iov(&iovw, &IOVEC_MAKE_STRING("ccc")));
ASSERT_EQ(iovw.count, 3U);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa")), 0);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb")), 0);
- ASSERT_EQ(iovec_memcmp(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc")), 0);
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa")));
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb")));
+ ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc")));
}
TEST(iovw_extend_iovw) {
ASSERT_OK(iovw_put(&iovw, (char*) "bar", 4));
ASSERT_OK(iovw_concat(&iovw, &iov));
- ASSERT_EQ(iovec_memcmp(&iov, &IOVEC_MAKE("foo\0bar\0", 8)), 0);
+ ASSERT_TRUE(iovec_equal(&iov, &IOVEC_MAKE("foo\0bar\0", 8)));
}
TEST(iovw_to_cstring) {
assert_se(json_variant_unbase64_iovec(sd_json_variant_by_key(j, "nr1"), &a) >= 0);
assert_se(json_variant_unhex_iovec(sd_json_variant_by_key(j, "nr2"), &b) >= 0);
- assert_se(iovec_memcmp(&iov1, &a) == 0);
- assert_se(iovec_memcmp(&iov2, &b) == 0);
+ assert_se(iovec_equal(&iov1, &a));
+ assert_se(iovec_equal(&iov2, &b));
assert_se(iovec_memcmp(&iov2, &a) < 0);
assert_se(iovec_memcmp(&iov1, &b) > 0);
}
for (size_t i = 0; i < n; i++)
if (i < m)
- ASSERT_EQ(iovec_memcmp(&iovec[i], &IOVEC_MAKE_STRING(v[i])), 0);
+ ASSERT_TRUE(iovec_equal(&iovec[i], &IOVEC_MAKE_STRING(v[i])));
else {
- ASSERT_EQ(iovec_memcmp(&iovec[i], &IOVEC_MAKE_STRING(expected[i - m])), 0);
+ ASSERT_TRUE(iovec_equal(&iovec[i], &IOVEC_MAKE_STRING(expected[i - m])));
free(iovec[i].iov_base);
}
for (size_t i = 0; i < n; i++)
if (i < m)
- ASSERT_EQ(iovec_memcmp(&iovec[i], &IOVEC_MAKE_STRING(v[i])), 0);
+ ASSERT_TRUE(iovec_equal(&iovec[i], &IOVEC_MAKE_STRING(v[i])));
else if ((i - m) % 2 == 0) {
- ASSERT_EQ(iovec_memcmp(&iovec[i], &IOVEC_MAKE_STRING(expected[(i - m) / 2])), 0);
+ ASSERT_TRUE(iovec_equal(&iovec[i], &IOVEC_MAKE_STRING(expected[(i - m) / 2])));
free(iovec[i].iov_base);
} else
- ASSERT_EQ(iovec_memcmp(&iovec[i], &IOVEC_MAKE_STRING("\n")), 0);
+ ASSERT_TRUE(iovec_equal(&iovec[i], &IOVEC_MAKE_STRING("\n")));
}
#define test_log_format_iovec_one(...) \
&srk,
&unsealed_secret) >= 0);
- assert_se(iovec_memcmp(&secret, &unsealed_secret) == 0);
+ assert_se(iovec_equal(&secret, &unsealed_secret));
}
static void check_seal_unseal(Tpm2Context *c) {