Skip to content
Open
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: 1 addition & 3 deletions lib/posix/c_lib_ext/fnmatch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: BSD-3-Clause */

Check warning on line 1 in lib/posix/c_lib_ext/fnmatch.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

lib/posix/c_lib_ext/fnmatch.c:1 License file for 'BSD-3-Clause' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.

Check warning on line 1 in lib/posix/c_lib_ext/fnmatch.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

lib/posix/c_lib_ext/fnmatch.c:1 License file for 'BSD-3-Clause' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.

Check warning on line 1 in lib/posix/c_lib_ext/fnmatch.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

lib/posix/c_lib_ext/fnmatch.c:1 License file for 'BSD-3-Clause' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.

/* $NetBSD: fnmatch.c,v 1.26 2014/10/12 22:32:33 christos Exp $ */

Expand Down Expand Up @@ -90,9 +90,7 @@
}

if (c == '\\' && !(flags & FNM_NOESCAPE)) {
if (*pattern != ']' && *pattern != EOS) {
c = FOLDCASE(*pattern++, flags);
}
c = FOLDCASE(*pattern++, flags);
}

if (c == EOS) {
Expand Down
27 changes: 25 additions & 2 deletions tests/posix/c_lib_ext/src/fnmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,31 @@ ZTEST(posix_c_lib_ext, test_fnmatch)
zassert_equal(fnmatch("a*.c", "a/x.c", FNM_PATHNAME), FNM_NOMATCH);
zassert_ok(fnmatch("*/foo", "/foo", FNM_PATHNAME));
zassert_ok(fnmatch("-O[01]", "-O1", 0));
zassert_ok(fnmatch("[[?*\\]", "\\", 0));
zassert_ok(fnmatch("[]?*\\]", "]", 0));
/*
* '\' in pattern escapes ']'. bracket expression is incomplete. pattern is interpreted as
* literal sequence '[[?*\]'. which does not match input '\'
*/
zassert_equal(fnmatch("[[?*\\]", "\\", 0), FNM_NOMATCH);
/* '\' in pattern does not escape ']'. bracket expression complete. '\' matches input '\' */
zassert_ok(fnmatch("[[?*\\]", "\\", FNM_NOESCAPE));
/* '\' in pattern escapes '\', match '\' */
zassert_ok(fnmatch("[[?*\\\\]", "\\", 0));
/*
* "[]" (empty bracket expression) is an invalid pattern.
* > The ( ']' ) shall lose its special meaning and represent itself in a bracket expression
* > if it occurs first in the list (after an initial ( '^' ), if any)
* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_05
*
* So the next test is (again) and incomplete bracket expression and should return error.
* The two tests that follow it also require the ']' to be treated as a literal character to
* match within the bracket expression.
*/
zassert_equal(fnmatch("[]?*\\]", "]", 0), FNM_NOMATCH);
/* '\' in pattern does not escape. bracket expression complete. ']' matches input ']' */
zassert_ok(fnmatch("[]?*\\]", "]", FNM_NOESCAPE));
/* '\' in pattern escapes '\'. bracket expression complete. ']' matches input ']' */
zassert_ok(fnmatch("[]?*\\\\]", "]", 0));

zassert_ok(fnmatch("[!]a-]", "b", 0));
zassert_ok(fnmatch("[]-_]", "^", 0));
zassert_ok(fnmatch("[!]-_]", "X", 0));
Expand Down
Loading