Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-4244: Fix RlistEqual comparison on lists of different lengths #5313

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libpromises/rlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ bool RlistEqual(const Rlist *list1, const Rlist *list2)
assert(rp1->val.item == NULL && rp2->val.item == NULL);
}
}

return true;
// return false if lengths are different
return (rp1 == NULL && rp2 == NULL);
}

bool RlistEqual_untyped(const void *list1, const void *list2)
Expand Down
41 changes: 41 additions & 0 deletions tests/acceptance/01_vars/04_containers/execresult_and_as_data.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#######################################################
#
# Test the ability to call the same command with execresult and execresult_as_data
#
#######################################################

body common control
{
inputs => { "../../default.cf.sub" };
bundlesequence => { default("$(this.promise_filename)") };
version => "1.0";
}

#######################################################


bundle agent init
{
}

#######################################################

bundle agent test
{
vars:
!windows::
"res1" string => execresult("echo test", "useshell");
"res2" data => execresult_as_data("echo test", "useshell", "stdout");
windows::
"res1" string => execresult("echo test", "powershell");
"res2" data => execresult_as_data("echo test", "powershell", "stdout");
}


#######################################################

bundle agent check
{
methods:
"any" usebundle => dcs_check_strcmp("${test.res1}", "${test.res2[output]}", "$(this.promise_filename)", "no");
}
18 changes: 18 additions & 0 deletions tests/unit/rlist_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ static void test_length(void)
RlistDestroy(list);
}

static void test_equality(void)
{
Rlist *list1 = RlistFromSplitString("a,b,c", ',');
Rlist *list2 = RlistFromSplitString("a,b,c", ',');
Rlist *list3 = RlistFromSplitString("z,b,c", ',');
Rlist *list4 = RlistFromSplitString("a,b,c,d", ',');

assert_true(RlistEqual(list1, list2));
assert_false(RlistEqual(list1, list3));
assert_false(RlistEqual(list1, list4));

RlistDestroy(list1);
RlistDestroy(list2);
RlistDestroy(list3);
RlistDestroy(list4);
}

static void test_prepend_scalar_idempotent(void)
{
Rlist *list = NULL;
Expand Down Expand Up @@ -750,6 +767,7 @@ int main()
{
unit_test(test_prepend_scalar_idempotent),
unit_test(test_length),
unit_test(test_equality),
unit_test(test_copy),
unit_test(test_rval_to_scalar),
unit_test(test_rval_to_scalar2),
Expand Down
Loading