summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoseph Sutton <josephsutton@catalyst.net.nz>2022-05-11 14:06:22 +1200
committerAndrew Bartlett <abartlet@samba.org>2022-06-09 22:49:29 +0000
commit222e1afc6f9a49e99ae767d7572dfd16c236148d (patch)
treec1a9b5a6c85f28bb1e3597df3a8cb59572b7d1da /lib
parenta80d783a341fd8b88d73e04bf831b91984f87b73 (diff)
downloadsamba-222e1afc6f9a49e99ae767d7572dfd16c236148d.tar.gz
lib/util: Add test of mem_equal_const_time()
Ensure that it gives the correct results for comparing two memory regions. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/tests/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c
index 03f62974c3f..0b69e215f82 100644
--- a/lib/util/tests/util.c
+++ b/lib/util/tests/util.c
@@ -426,6 +426,25 @@ done:
return ret;
}
+static bool test_mem_equal_const_time(struct torture_context *tctx)
+{
+ const char *test_string = "abcdabcd";
+
+ torture_assert(tctx, mem_equal_const_time("", "", 0),
+ "zero-length comparison failed");
+
+ torture_assert(tctx, mem_equal_const_time(test_string, test_string, 8),
+ "comparison with equal pointers failed");
+
+ torture_assert(tctx, mem_equal_const_time(test_string, test_string + 4, 4),
+ "comparison with non-equal pointers failed");
+
+ torture_assert(tctx, !mem_equal_const_time("abcd", "efgh", 4),
+ "comparison with different values failed");
+
+ return true;
+}
+
static bool test_smb_strtoul_errno_check(struct torture_context *tctx)
{
const char *number = "123";
@@ -609,6 +628,9 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx)
"directory_create_or_exist",
test_directory_create_or_exist);
torture_suite_add_simple_test(suite,
+ "mem_equal_const_time",
+ test_mem_equal_const_time);
+ torture_suite_add_simple_test(suite,
"smb_strtoul(l) errno",
test_smb_strtoul_errno_check);
torture_suite_add_simple_test(suite,