Before modifying semanage_split_on_space() and semanage_split(), test in test_utilities.c how these functions behave for example when several delimiter tokens are concatenated in the input string. While at it, fix the memory leaks which were present in libsemanage tests. Signed-off-by: Nicolas Iooss <nicolas.iooss@xxxxxxx> --- libsemanage/tests/test_utilities.c | 51 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/libsemanage/tests/test_utilities.c b/libsemanage/tests/test_utilities.c index 32cc33c1b510..b46f18db2a99 100644 --- a/libsemanage/tests/test_utilities.c +++ b/libsemanage/tests/test_utilities.c @@ -129,7 +129,7 @@ void test_semanage_is_prefix(void) void test_semanage_split_on_space(void) { - char *str = strdup("foo bar baz"); + char *str = strdup(" foo bar baz"); char *temp; if (!str) { @@ -137,24 +137,24 @@ void test_semanage_split_on_space(void) ("semanage_split_on_space: unable to perform test, no memory"); } temp = semanage_split_on_space(str); - if (strncmp(temp, "bar", 3)) { - CU_FAIL("semanage_split_on_space: token did not match"); - } - temp = semanage_split_on_space(temp); - if (strncmp(temp, "baz", 3)) { - CU_FAIL("semanage_split_on_space: token did not match"); - } - temp = semanage_split_on_space(temp); - if (strcmp(temp, "")) { - CU_FAIL("semanage_split_on_space: token did not match"); - } + CU_ASSERT_STRING_EQUAL(temp, "bar baz"); + free(str); + str = temp; + + temp = semanage_split_on_space(str); + CU_ASSERT_STRING_EQUAL(temp, "baz"); + free(str); + str = temp; + temp = semanage_split_on_space(str); + CU_ASSERT_STRING_EQUAL(temp, ""); free(str); + free(temp); } void test_semanage_split(void) { - char *str = strdup("foo1 foo2 foo:bar"); + char *str = strdup("foo1 foo2 foo:bar:"); char *temp; if (!str) { @@ -163,13 +163,24 @@ void test_semanage_split(void) return; } temp = semanage_split(str, NULL); - CU_ASSERT_NSTRING_EQUAL(temp, "foo2", 4); - temp = semanage_split(temp, ""); - CU_ASSERT_NSTRING_EQUAL(temp, "foo", 3); - temp = semanage_split(temp, ":"); - CU_ASSERT_NSTRING_EQUAL(temp, "bar", 3); + CU_ASSERT_STRING_EQUAL(temp, "foo2 foo:bar:"); + free(str); + str = temp; + temp = semanage_split(str, ""); + CU_ASSERT_STRING_EQUAL(temp, "foo:bar:"); free(str); + str = temp; + + temp = semanage_split(str, ":"); + CU_ASSERT_STRING_EQUAL(temp, "bar:"); + free(str); + str = temp; + + temp = semanage_split(str, ":"); + CU_ASSERT_STRING_EQUAL(temp, ""); + free(str); + free(temp); } void test_semanage_list(void) @@ -242,6 +253,8 @@ void test_semanage_rtrim(void) CU_ASSERT_STRING_EQUAL(str, "/blah/foo/bar/b"); semanage_rtrim(str, '/'); CU_ASSERT_STRING_EQUAL(str, "/blah/foo/bar"); + + free(str); } void test_semanage_findval(void) @@ -252,6 +265,7 @@ void test_semanage_findval(void) } tok = semanage_findval(fname, "one", NULL); CU_ASSERT_STRING_EQUAL(tok, ""); + free(tok); rewind(fptr); tok = semanage_findval(fname, "one", ""); CU_ASSERT_STRING_EQUAL(tok, ""); @@ -259,6 +273,7 @@ void test_semanage_findval(void) rewind(fptr); tok = semanage_findval(fname, "sigma", "="); CU_ASSERT_STRING_EQUAL(tok, "foo"); + free(tok); } int PREDICATE(const char *str) -- 2.11.0 _______________________________________________ Selinux mailing list Selinux@xxxxxxxxxxxxx To unsubscribe, send email to Selinux-leave@xxxxxxxxxxxxx. To get help, send an email containing "help" to Selinux-request@xxxxxxxxxxxxx.