From: Michael Tremer Date: Fri, 9 Dec 2022 13:19:59 +0000 (+0000) Subject: filelist: Make pattern matching less eager X-Git-Tag: 0.9.28~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04fbda35aa4f432660a921a65637501cf3ba7938;p=pakfire.git filelist: Make pattern matching less eager Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index ec1951d33..8d38aff01 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -175,6 +175,7 @@ static int is_glob(const char* s) { } static int pakfire_filelist_match_patterns(const char* path, const char** patterns) { + int flags = 0; int r; for (const char** pattern = patterns; *pattern; pattern++) { @@ -186,7 +187,20 @@ static int pakfire_filelist_match_patterns(const char* path, const char** patter if (!is_glob(*pattern)) continue; - r = fnmatch(*pattern, path, 0); + // Reset flags + flags = 0; + + /* + fnmatch is way too eager for patterns line /usr/lib/*.so which will also match + things like /usr/lib/python3.x/blah/blubb.so. + To prevent this for absolute file paths, we set the FNM_FILE_NAME flag so that + asterisk (*) won't match any slashes (/). + */ + if (**pattern == '/') + flags |= FNM_FILE_NAME; + + // Perform matching + r = fnmatch(*pattern, path, flags); // Found a match if (r == 0)