From 588c1ff04724e1425f443d20b8ed2ff1641cc51c Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Mon, 16 Feb 2026 11:48:01 +0100 Subject: [PATCH 1/2] Fixed missing directory file separator suffix Ticket: CFE-4623 Signed-off-by: Victor Moene --- libutils/glob_lib.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libutils/glob_lib.c b/libutils/glob_lib.c index 1c057d82..adb47187 100644 --- a/libutils/glob_lib.c +++ b/libutils/glob_lib.c @@ -432,7 +432,7 @@ static void PathWalkCallback( { /* We have matched each and every part of the glob pattern, thus we * have a full match. */ - char *const match = xstrdup(dirpath); + char *const match = StringFormat("%s" FILE_SEPARATOR_STR, dirpath); SeqAppend(data->matches, match); Log(LOG_LEVEL_DEBUG, "Full match! Directory '%s' has matched all previous sub patterns", @@ -675,11 +675,18 @@ StringSet *GlobFileList(const char *pattern) free(expanded); expanded = tmp; + struct stat sb; if (glob(expanded, 0, NULL, &globbuf) == 0) { for (size_t j = 0; j < globbuf.gl_pathc; j++) { - StringSetAdd(set, SafeStringDuplicate(globbuf.gl_pathv[j])); + if (stat(globbuf.gl_pathv[j], &sb) != 1) + { + char *path = S_ISDIR(sb.st_mode) + ? StringFormat("%s" FILE_SEPARATOR_STR, globbuf.gl_pathv[j]) + : SafeStringDuplicate(globbuf.gl_pathv[j]); + StringSetAdd(set, path); + } } globfree(&globbuf); } From 205348763f9f05be18c70a64539c18d313900ce7 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Mon, 16 Feb 2026 15:22:31 +0100 Subject: [PATCH 2/2] Fixed unit tests for directory separator suffix --- tests/unit/glob_lib_test.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/unit/glob_lib_test.c b/tests/unit/glob_lib_test.c index 5457bfcf..4dba2ce0 100644 --- a/tests/unit/glob_lib_test.c +++ b/tests/unit/glob_lib_test.c @@ -271,7 +271,7 @@ static void test_glob_find(void) { Seq *const matches = GlobFind("."); assert_int_equal(SeqLength(matches), 1); - assert_string_equal(SeqAt(matches, 0), "."); + assert_string_equal(SeqAt(matches, 0), "." FILE_SEPARATOR_STR); SeqDestroy(matches); } } @@ -289,10 +289,10 @@ static void test_glob_file_list(void) // Create test subdirectories. static const char *const test_subdirs[] = { - "foo", - "foo" FILE_SEPARATOR_STR "bar", - "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR "baz", - "qux", + "foo" FILE_SEPARATOR_STR, + "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, + "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR "baz" FILE_SEPARATOR_STR, + "qux" FILE_SEPARATOR_STR, }; const size_t num_test_subdirs = sizeof(test_subdirs) / sizeof(const char *); @@ -471,14 +471,14 @@ static void test_glob_file_list(void) matches = GlobFileList(pattern); assert_int_equal(StringSetSize(matches), 4); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); ret = snprintf( path, PATH_MAX, - "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar", + "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); @@ -487,12 +487,12 @@ static void test_glob_file_list(void) path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR - "bar" FILE_SEPARATOR_STR "baz", + "bar" FILE_SEPARATOR_STR "baz" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "qux", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "qux" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); @@ -676,14 +676,14 @@ static void test_glob_file_list(void) assert_int_equal(StringSetSize(matches), 2); - ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo", test_dir); + ret = snprintf(path, PATH_MAX, "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path)); ret = snprintf( path, PATH_MAX, - "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar", + "%s" FILE_SEPARATOR_STR "foo" FILE_SEPARATOR_STR "bar" FILE_SEPARATOR_STR, test_dir); assert_true(ret < PATH_MAX && ret >= 0); assert_true(StringSetContains(matches, path));