From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54575374E48 for ; Sun, 15 Mar 2026 17:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594675; cv=pass; b=doVphkghODwgT/pwyWj9yXwLSXnG8gaUgeu0/0bGSvE/Wie9xcu2mSP2YoiyFD9Cwmjmurl66qOfuTO/icF5gxsjd1xN+eyubvmlAZcDmwWT3ZdBgIEaxmQsOwn7yOPqcgLCBsBcSyVNB3vnlVskRS4hINT1i/KXLMRkDXIaQzA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594675; c=relaxed/simple; bh=TvoodWqX4Zt9qaZn8/cmtP96TLJg6Fl3uNkMx+/OM/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ceTnXadeFeFcIbopZhI+Zp25zk3xTHc7xZzojLnXBQJJTqdLqoOIfrBo3rSNb3c1Cu2WtDng7MCxWBZ1tIrIZhENi7nFybSIZHCC3kVQlIVMYVwrcVNeew8SCRxp1zUXJho+XUTh6TXzP/QzWYR7SfGC4oA9DKLx1xoSQcfjhlk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=Rac2q6iY; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="Rac2q6iY" ARC-Seal: i=1; a=rsa-sha256; t=1773594669; cv=none; d=zohomail.eu; s=zohoarc; b=dR3F2p/X9N9tWcQ0qmfoic/u4I3le+VZffInZyyNm9EZ8TdDXBI83bpbcpWKwIJl+bKBo2b8JR7Cc9mmdhF5WgdHjNMzHoxlPDavfWN0UHX3FWkqEpmMwUhdKJwFmvPZ5PFK+e62XbKV5gASyz8GUy/aIBoARhIOWQ12nQKoWEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594669; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=IKJGSUF4neu8mf6CKhF1x8j3j8JrAeeYnr9Wq9xiqSo=; b=BHSGgq9Etwmd4NjzovwMqoR52Nn2a9KyGd0L+rGMgQ3hl8zJCGPvQNJ11mUKU9oZGYloPZkZIaNUoyAZOSHEykEi3Rhyy2L1mSDSqIV+w98E+9grEBN6IgA4WEMz2v/7yIEb1vkusANCE6ByIlFB3c6s4k3hblBwsjue1uDDVtM= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594669; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=IKJGSUF4neu8mf6CKhF1x8j3j8JrAeeYnr9Wq9xiqSo=; b=Rac2q6iYNXMtjtm4wMWwMQVkZsCdEaX+KQB/TsdCiv6dBWP6PJS3dUMQ2uRtH3+f ikAzRViPeknvyt5RER6uUZgu9sL1FT7t1o6K6p6/k2EkMfbWMlszfXeheKhDygdo+yy VFDfdGHpq0ftDtJiDbBa/uROsnVlbyb8td+oZc4M= Received: by mx.zoho.eu with SMTPS id 1773594667152528.1242515151395; Sun, 15 Mar 2026 18:11:07 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/7] lib/glob: normalize inverted character class ranges Date: Sun, 15 Mar 2026 17:10:58 +0000 Message-Id: <20260315171104.268944-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" When a character class range has its endpoints reversed (e.g., [z-a]), the comparison a <=3D c && c <=3D b can never be true, so the range silently matches nothing. A pattern like "file[9-0]" intended to match any digit would fail to match anything, with no indication that the range is backwards. Swap the endpoints when a > b so that inverted ranges behave the same as their forward equivalents: [z-a] matches the same characters as [a-z], and [9-0] matches the same as [0-9]. This is consistent with how GNU fnmatch and other glob implementations handle reversed ranges. Signed-off-by: Josh Law --- lib/glob.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/glob.c b/lib/glob.c index 7aca76c25bcb..cb45a9a47f28 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -94,7 +94,13 @@ bool __pure glob_match(char const *pat, char const *str) goto literal; =20 class +=3D 2; - /* Any special action if a > b? */ + /* Normalize inverted ranges like [z-a] */ + if (a > b) { + unsigned char tmp =3D a; + + a =3D b; + b =3D tmp; + } } if (a <=3D c && c <=3D b) match =3D true; --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F44B374756 for ; Sun, 15 Mar 2026 17:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594674; cv=pass; b=dhZF1x5euIkioR937bTEntRdy5iXbtAKRyYBalLNIqFnRoKiktfJg7Zgtk4mdCKUpHt05HeF846Iu4Q15PpPT393Exg5XqNI4t2qhkh1CgsXce7IXZhfiUxVUFQdiYBHTHiv+nC0a7xckpE62GN8vPnJ3LzjhrI361YYHgqsdM0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594674; c=relaxed/simple; bh=ynosWAVdTZjwHIldBKnJyOHFf6YCnzrYK/oMhyqjJmI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MISI9snKtn6T+Hs8dKcQIvQYPlo537HS2x06v6NrBfsoBOBosDo7ynlOb1T9jbZFT9KeRxSeuLgxkEWWl3LI/5HTHLo4yFhit59R52dtmnkvtEzisFjrcUIlY20DQO6/UdhAZtfXW33opgcr+BNuRKkrqhDKL39Sy4mf1T5hIGg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=IHtN42lC; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="IHtN42lC" ARC-Seal: i=1; a=rsa-sha256; t=1773594669; cv=none; d=zohomail.eu; s=zohoarc; b=UHtOPDacwTiWvD6Rj/gRJymWicQ/H+L3kkrXkzsfEZz6ISNRyljaocCjPbQd6QoyJReoddsIVFBext6AaRaLGzmP0q5BxRMWfDjC12+N5+X2JhxgddsGHaHBC83O+LNqsdf16Ne7n5kcxrMFjS5XmRZL2LcahwAYycV4O6OKx+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594669; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=ueSZI5AfyJ2dJY/ym+gJvwLv50twR0Whfk1qSI94zoM=; b=kmkbb1RJLYpw73B7SknZ3vcGXM+FliFhnhuBvP5tOz7VgCCRQ9Oq8oN6ZEdOVvK6ykAekAGYsBkoyUJ9MHgeXYYYz9emhnj5fCwMq7DLSUsVHN6ZncFA7o5cvxB2efGD4ENTmj/BwjNxx6SufHl/34tAAop6xqJJFwj4y8CJHwk= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594669; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=ueSZI5AfyJ2dJY/ym+gJvwLv50twR0Whfk1qSI94zoM=; b=IHtN42lC3ZADYl+r1eTTosvPNLu7NCZRpqPPhmaxmcypa7tPoL8yQ+/0CNCPvTCM lDKpLmUXgFayKKDHAxubnFvILYMvkfbPUCKO2cEcmQ03qU+MyLuCqANyGASpHhUkRfC +3IwMWhEQm9Lq87LgD4GEsOK9h9tcwbuBqksOVTw= Received: by mx.zoho.eu with SMTPS id 1773594667541263.5769287920301; Sun, 15 Mar 2026 18:11:07 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/7] lib/glob: treat trailing backslash as literal character Date: Sun, 15 Mar 2026 17:10:59 +0000 Message-Id: <20260315171104.268944-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" A pattern ending with a lone backslash (e.g., "path\\") reads the NUL terminator as the escaped character, making the backslash effectively match end-of-string rather than a literal '\' character. This means glob_match("path\\", "path\\") would fail since the pattern consumes the NUL early, while glob_match("path\\", "path") would unexpectedly succeed. Guard the escape so that a trailing backslash keeps d =3D '\\' and falls through to literal matching, which is the intuitive behavior: a trailing backslash matches a literal backslash character. Signed-off-by: Josh Law --- lib/glob.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/glob.c b/lib/glob.c index cb45a9a47f28..df7f00619b1b 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -112,7 +112,8 @@ bool __pure glob_match(char const *pat, char const *str) } break; case '\\': - d =3D *pat++; + if (*pat !=3D '\0') + d =3D *pat++; fallthrough; default: /* Literal character */ literal: --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59BB7374E62 for ; Sun, 15 Mar 2026 17:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594675; cv=pass; b=Y1kOLkGPBpyDiqKQdsrAZ0OXJNEsH9fdbLf3SHLzvHiIGuxip0F5j8RZonlCki4KPODaM5rgVmubTeWxOvPQ4mY8OgFBesNWg7nMqHUFtC0MYfjQYcnIjoPhEYFdF7vnspfV2LM6kMUYnfP3xbvRJwl8Ado1voMrbb29k4RV6F4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594675; c=relaxed/simple; bh=XgWFRb8ONcA2GQ/HdeRNANjgs9ScGEr/4d+esA/Kb7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oeN/SbroLzh/CdR2vTd1WfQhug7rtu2r8OitGg9N5JZ+Y00utDU45Cxzy71e4OWuQ+KUsjWIeFfB73Iu70a+EsfTvuXGFeQh+RlBBFoWuVCzWjYA/VuGs1ztZq4WWU6a11mhzxF7d+UBQtTQT7nyuJ8cvExXsDQJB+ts1EdWKM4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=UOtZgMH/; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="UOtZgMH/" ARC-Seal: i=1; a=rsa-sha256; t=1773594669; cv=none; d=zohomail.eu; s=zohoarc; b=ZCZwAf/yf5DOf2iMjPNfQ5DwgHsM5VF7PFbfiyMXwp1GIsKB3SbQc5D9MNzFbl2GlMu+kYiOm4GJwFWoqM/b3sPX/u6c5HgR2fSwL2RhlzJXbAFBk6YwFrRIwVjoGmq79Ihl/RIlu6RMiE7ZmgMzPiMxePyTzTuLMahoupanXV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594669; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=6MFsWg559qWHVDZpDzdEbMHixOdjZsqRsUni07ha0iI=; b=S+IRbAvB4+mBYmZal8o/Q4KPYDioEMW8vRuMy12nimtKifgnFPza+t3skAF9X+W3OsMepfyf7asdP5EsFYCWmdFLDK3dC17QO8mDENwMgxBJnY/aSw5SWbgw8vyrSXn4vMCzWErOW48hI4tPKku454tQER3diyRjIUsgRydej+4= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594669; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=6MFsWg559qWHVDZpDzdEbMHixOdjZsqRsUni07ha0iI=; b=UOtZgMH/r5BWkWSE8+Hxjgi69SDVYAhsAzj6wb+Ehe/bYEFSpOFE9Zqqoi9tHuqj 7gz/O6rXcs531KhREYQI6zyob+IC4UK2A24o788NHCC6KI+mWkpK1/rp6C+R16/8zw6 CzkxzBbc0seuFgLkBYEhOyybnJYwJEgBm1q0j8hI= Received: by mx.zoho.eu with SMTPS id 1773594667929445.6718407235394; Sun, 15 Mar 2026 18:11:07 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/7] lib/glob: accept [^...] as character class negation syntax Date: Sun, 15 Mar 2026 17:11:00 +0000 Message-Id: <20260315171104.268944-4-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" glob(7) specifies [!...] for negated character classes, but many users are more familiar with the regex-style [^...] syntax. Tools like git, rsync, and bash all accept both forms, and the difference is a common source of confusion when writing glob patterns. Accept '^' as an alias for '!' at the start of a character class so that both [!a-z] and [^a-z] work as expected. Signed-off-by: Josh Law --- lib/glob.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/glob.c b/lib/glob.c index df7f00619b1b..c5508be0d215 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -33,9 +33,9 @@ MODULE_LICENSE("Dual MIT/GPL"); * Like !fnmatch(@pat, @str, 0) and unlike the shell, this does NOT * treat / or leading . specially; it isn't actually used for pathnames. * - * Note that according to glob(7) (and unlike bash), character classes - * are complemented by a leading !; this does not support the regex-style - * [^a-z] syntax. + * Note that according to glob(7), character classes are complemented by + * a leading !. The regex-style [^a-z] syntax is also accepted as an + * alias. * * An opening bracket without a matching close is matched literally. */ @@ -72,7 +72,7 @@ bool __pure glob_match(char const *pat, char const *str) case '[': { /* Character class */ if (c =3D=3D '\0') /* No possible match */ return false; - bool match =3D false, inverted =3D (*pat =3D=3D '!'); + bool match =3D false, inverted =3D (*pat =3D=3D '!' || *pat =3D=3D '^'); char const *class =3D inverted ? pat + 1 : pat; unsigned char a =3D *class++; =20 --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A673637186D for ; Sun, 15 Mar 2026 17:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594674; cv=pass; b=skM1IwAs1WCQtWEHBDEvcdeyRdqNDzA83ACNFZUrj/0gRW209j4eehT7XYYkQs4pHzcvRDPBWb+atD1vpGWAoOYu+v5t7UP1WYdly4oP0zqTDCLd+EOm5ZxryJa/jtJrPaMFa6yb5KIB6BZzj0EZ8rK8S23G7O7LUnDzRMKiA+8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594674; c=relaxed/simple; bh=oix+wiBJKF332wvXSw7Y+HX5VihV924T+Z6aMqcLgG0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aYRiMTiue4/KaJz2VVUVN/2jaabxUIn5A6Kvu2rcwAZOmGzjAZHrPDJyyXKFrpS4FYgiq/PiWScg4z6q1/UGYR1b4bGoXXtDdHLMGTZX1Cuq/KQkm5RYnXhAykDCnzQ7ajTZ2SQ10Lc9uAgf2bRWDeyy3FMt7GcYBG2CrKK3zVs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=IT2FR4FH; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="IT2FR4FH" ARC-Seal: i=1; a=rsa-sha256; t=1773594670; cv=none; d=zohomail.eu; s=zohoarc; b=VyHzcBa0XuiRIauwc5XfsmxaFDQF1/+cFyb+G1FuTIqT/NLLJU8HnYqw/qUOFTSF/wCT9tXtYfZAfXt6AvGzLr/BlPBanMwPFD1iYayvNck37jnRan86GZ7Ow7jVavlTWHch3X2AYW2PFZuU2QequBDZHAhneYKJCkkSyeMTmc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594670; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=m9VygHU2eW7/IuffMuqNIs8dFitaQscBHUGSVCKMQdg=; b=hyMqDaZR0xJ2+98Y0KU8hDYBO19snzvogYVbkSG0mWEqJfHxgHKiEE0yuL/gba42dalIdToVGt9X23HqFhLdFopQlqeCI3hn3hwbY/wOfcEMhz0Zkh4TBI43uM/xir+QaFI80EmOc5OV6ypFS43obfDwP0mrxRbx7u0KeWjQTPI= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594670; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=m9VygHU2eW7/IuffMuqNIs8dFitaQscBHUGSVCKMQdg=; b=IT2FR4FHeeOe5X0stAZ/YOmSS3WjzWJFHGcdL/XdWFSX0mTqcxMjwrlIbuaifwzu cQAwz/lwDh+czvfr0QZ/N3/x4kUC6D2eSO0gNG8Hcq4Uuf3aZdjn9DL/Qj5bzW52kr/ JLiDKETbb1Lh0HLpaYk9Hj0oKvBmqofhA7WMxahM= Received: by mx.zoho.eu with SMTPS id 1773594668314590.9692518906124; Sun, 15 Mar 2026 18:11:08 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/7] lib/glob: add case-insensitive glob_match_nocase() Date: Sun, 15 Mar 2026 17:11:01 +0000 Message-Id: <20260315171104.268944-5-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Add a case-insensitive variant of glob_match() for callers that need to match patterns regardless of case. For example, ATA device model strings or ftrace function filters may benefit from case-insensitive matching without requiring both the pattern and target string to be lowercased beforehand. Refactor the matching logic into a static __glob_match() helper that takes a bool nocase parameter, and implement both glob_match() and glob_match_nocase() as thin wrappers. When nocase is true, literal characters and character class endpoints are folded through tolower() before comparison. Signed-off-by: Josh Law --- include/linux/glob.h | 1 + lib/glob.c | 73 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/include/linux/glob.h b/include/linux/glob.h index 861327b33e41..36527ae89730 100644 --- a/include/linux/glob.h +++ b/include/linux/glob.h @@ -6,5 +6,6 @@ #include /* For __pure */ =20 bool __pure glob_match(char const *pat, char const *str); +bool __pure glob_match_nocase(char const *pat, char const *str); =20 #endif /* _LINUX_GLOB_H */ diff --git a/lib/glob.c b/lib/glob.c index c5508be0d215..9c71ccc15abc 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: (GPL-2.0 OR MIT) +#include #include #include #include @@ -11,8 +12,8 @@ MODULE_DESCRIPTION("glob(7) matching"); MODULE_LICENSE("Dual MIT/GPL"); =20 -/** - * glob_match - Shell-style pattern matching, like !fnmatch(pat, str, 0) +/* + * __glob_match - Shell-style pattern matching, like !fnmatch(pat, str, 0) * @pat: Shell-style pattern to match, e.g. "*.[ch]". * @str: String to match. The pattern must match the entire string. * @@ -39,7 +40,7 @@ MODULE_LICENSE("Dual MIT/GPL"); * * An opening bracket without a matching close is matched literally. */ -bool __pure glob_match(char const *pat, char const *str) +static bool __pure __glob_match(char const *pat, char const *str, bool noc= ase) { /* * Backtrack to previous * on mismatch and retry starting one @@ -58,6 +59,11 @@ bool __pure glob_match(char const *pat, char const *str) unsigned char c =3D *str++; unsigned char d =3D *pat++; =20 + if (nocase) { + c =3D tolower(c); + d =3D tolower(d); + } + switch (d) { case '?': /* Wildcard: anything but nul */ if (c =3D=3D '\0') @@ -94,13 +100,17 @@ bool __pure glob_match(char const *pat, char const *st= r) goto literal; =20 class +=3D 2; - /* Normalize inverted ranges like [z-a] */ - if (a > b) { - unsigned char tmp =3D a; + } + if (nocase) { + a =3D tolower(a); + b =3D tolower(b); + } + /* Normalize inverted ranges like [z-a] */ + if (a > b) { + unsigned char tmp =3D a; =20 - a =3D b; - b =3D tmp; - } + a =3D b; + b =3D tmp; } if (a <=3D c && c <=3D b) match =3D true; @@ -112,8 +122,11 @@ bool __pure glob_match(char const *pat, char const *st= r) } break; case '\\': - if (*pat !=3D '\0') + if (*pat !=3D '\0') { d =3D *pat++; + if (nocase) + d =3D tolower(d); + } fallthrough; default: /* Literal character */ literal: @@ -132,4 +145,44 @@ bool __pure glob_match(char const *pat, char const *st= r) } } } + +/** + * glob_match - Shell-style pattern matching, like !fnmatch(pat, str, 0) + * @pat: Shell-style pattern to match, e.g. "*.[ch]". + * @str: String to match. The pattern must match the entire string. + * + * Perform shell-style glob matching, returning true (1) if the match + * succeeds, or false (0) if it fails. Equivalent to !fnmatch(@pat, @str,= 0). + * + * Pattern metacharacters are ?, *, [ and \. + * (And, inside character classes, !, ^ - and ].) + * + * This is small and simple and non-recursive, with run-time at most + * quadratic: strlen(@str)*strlen(@pat). It does not preprocess the + * patterns. An opening bracket without a matching close is matched + * literally. + * + * Return: true if @str matches @pat, false otherwise. + */ +bool __pure glob_match(char const *pat, char const *str) +{ + return __glob_match(pat, str, false); +} EXPORT_SYMBOL(glob_match); + +/** + * glob_match_nocase - Case-insensitive shell-style pattern matching + * @pat: Shell-style pattern to match. + * @str: String to match. The pattern must match the entire string. + * + * Identical to glob_match(), but performs case-insensitive comparisons + * for literal characters and character class contents using tolower(). + * Metacharacters (?, *, [, ]) are not affected by case folding. + * + * Return: true if @str matches @pat (case-insensitive), false otherwise. + */ +bool __pure glob_match_nocase(char const *pat, char const *str) +{ + return __glob_match(pat, str, true); +} +EXPORT_SYMBOL(glob_match_nocase); --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53D243750C7 for ; Sun, 15 Mar 2026 17:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594676; cv=pass; b=gL6T6H5jA/TMoxfqDqavgWvXEdocZDAzNXjh2zoyaU7H3sRczsrNGaAZAaO+hPt7p/7DfHCy7QCKvMyA+ViSZo5ZZzeZGSYrbsjaumUh9YnijTLSkkDx2xw/k2uoPUElISXqEvEtR5wmTXFlxih/eO/xZVbWI8g4AfR46IFB4PI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594676; c=relaxed/simple; bh=MPc6BFCGSACM368hqh07vzRexP5rxqkSUbTOB1V8GJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kjknN3ncwxs24uCiwPjPAn7M4Ha7diMosAyWQ+MdFQbyxd/dk0Z0Fu1sTf0OGedgSpu4g2Jsk4Y0oh+4QWeFSVb5ydZbKzXj9hA+lh1diu7uuI+Na+ZJRrxCRLdOh2OHS5KXo+RTe8iYJ+yubfzhLsBMd+eV6i//GvpXWZV0AfI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=iig0lktX; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="iig0lktX" ARC-Seal: i=1; a=rsa-sha256; t=1773594671; cv=none; d=zohomail.eu; s=zohoarc; b=c/a/BaqkZtlDyXznkcFrqBzjQKaeRZDRMRQkR09d57nn9P5SSonKVa5vpvK4xtmIa1a6w+mq9vggYPk/Fo/NH8xedcizK4OAaYOShFhPNDUyA8fOxZg2Rsbp2j1lNANEbx3QULnSiSAikBwT1e/jdWxSMrwzM+YfSQPrSSeCjpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=2WBm7tkyxyrrzugqbtjBKtsFz7871CMH0LPPBAiszcQ=; b=dZeu69cbb9OOrntbkp9qAQQxXrahSl4mi6mt9ZUV6l/3oq4g8mFP9FlOE0VWXQBwCRSnMxGExE7oqGhVAQa+/XusjqCrBUKc10El+NhaaUgbvZI8CqUU+QtU2CQ2HmlP5zdOAOAOLO0UftVnLQhrU6akppUTbFAqSNenm0IUzKQ= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594671; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=2WBm7tkyxyrrzugqbtjBKtsFz7871CMH0LPPBAiszcQ=; b=iig0lktXXzuu2hdugq+T/lA8PSlIixquwm8L50caDv3V44bR/fXTC/tZbCW2ddR5 gF4GjMR90Ll8ZmDJDmNgaKaoHpBaRvC3K3AVayZLAWqT/a8Clk8hjvhvp8KDoYAhHzM 5Io6Gg6/O3qTykW0d/odJIE/b109SZ8vUkir2kxM= Received: by mx.zoho.eu with SMTPS id 1773594668734874.9668942742104; Sun, 15 Mar 2026 18:11:08 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/7] lib/glob: add glob_validate() for pattern syntax checking Date: Sun, 15 Mar 2026 17:11:02 +0000 Message-Id: <20260315171104.268944-6-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Add glob_validate() which checks whether a glob pattern is syntactically well-formed before matching. It detects: - Unclosed character classes: a '[' with no matching ']' - Trailing backslash: a '\' at end of pattern with nothing to escape glob_match() already handles these gracefully (unclosed brackets are matched literally, a trailing backslash matches itself), but callers like ftrace filters or sysfs attribute stores that accept patterns from userspace may want to reject malformed input upfront with a clear error rather than silently falling back to literal matching. Signed-off-by: Josh Law --- include/linux/glob.h | 1 + lib/glob.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/glob.h b/include/linux/glob.h index 36527ae89730..deceaa2e4a74 100644 --- a/include/linux/glob.h +++ b/include/linux/glob.h @@ -7,5 +7,6 @@ =20 bool __pure glob_match(char const *pat, char const *str); bool __pure glob_match_nocase(char const *pat, char const *str); +bool __pure glob_validate(char const *pat); =20 #endif /* _LINUX_GLOB_H */ diff --git a/lib/glob.c b/lib/glob.c index 9c71ccc15abc..800163ed4dbf 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -186,3 +186,47 @@ bool __pure glob_match_nocase(char const *pat, char co= nst *str) return __glob_match(pat, str, true); } EXPORT_SYMBOL(glob_match_nocase); + +/** + * glob_validate - Check whether a glob pattern is well-formed + * @pat: Shell-style pattern to validate. + * + * Return: true if @pat is a syntactically valid glob pattern, false + * if it contains malformed constructs. The following are considered + * invalid: + * + * - An opening '[' with no matching ']' (unclosed character class). + * - A trailing '\' with no character following it. + * + * Note that glob_match() handles these gracefully (an unclosed bracket + * is matched literally, a trailing backslash matches itself), but + * callers that accept patterns from user input may wish to reject + * malformed patterns early with a clear error. + */ +bool __pure glob_validate(char const *pat) +{ + while (*pat) { + switch (*pat++) { + case '\\': + if (*pat =3D=3D '\0') + return false; + pat++; + break; + case '[': { + if (*pat =3D=3D '!' || *pat =3D=3D '^') + pat++; + /* ] as first character is literal, not end of class */ + if (*pat =3D=3D ']') + pat++; + while (*pat && *pat !=3D ']') + pat++; + if (*pat =3D=3D '\0') + return false; + pat++; /* skip ']' */ + break; + } + } + } + return true; +} +EXPORT_SYMBOL(glob_validate); --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53DB13750C8 for ; Sun, 15 Mar 2026 17:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594676; cv=pass; b=evDMGAwrewgDpUT9Zq3T2tweREaSJT08x3mAscNlBuaNKWduUvpFm8F5YL4l8zGsfRFRRZv3R7F6qjQ2vN3qsN4i+zPh6VGw6HsmLFOJwdg4554Vt4PlheBwbDeSegrrXeLUGPjVecq3FNIAkoE6w30LobkIasb8WvMESFZt1y8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594676; c=relaxed/simple; bh=DqDIHMd4MJlmLaUnm4FNNfD7TmiR4u66qXh4CXNuOwo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RYv+eVj6yziGP3pqCjT96M+pTyRnTtmIkVw03aM7uP+niyouMZ7vRi1F8Be87ayQAjjzfb/CO1LLaStt3vlfiGeezkXCC2vnvuDiPuuQozj3VB/uDdbmxdW2dxMCVyt3dC16h0GfRtZTl60BFe8MDOiJ0zWPhjsgSo7BT3JQVe4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=DGlUY1Nv; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="DGlUY1Nv" ARC-Seal: i=1; a=rsa-sha256; t=1773594671; cv=none; d=zohomail.eu; s=zohoarc; b=JwR2cmv30EAyMxUqYoUjAU5hbPIGMWWyuL5byFIzqmFl++8ThaOT5bHjpL4McIHBCpy0aAYsJWVIhECfzAMdgtcGH0sD/WDYuwxGCE/8Je6U8d5bXwmFCxWo/d1cl5//nwbO5i6/ptYsbL07iFBLXh2ToQM1F6s0oBEhkqXMkqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=f220kEhJ66X+jXJtp71OpS8vD3cCaDjeBL3VruhruPw=; b=DPsCkb0l5OZv78XP2lnzQrU8c71xBgk4zQvP35JtNajIvEdvtJUb6JeKJlSko7+/OaR6tcUPpm500jB8UjPjlWkR75Z6gnlAH6BdJdRAo+kcZPBwLeGWHENe2IosgTgV6uT8x3uZvjiShe/JVEGgqoHp1uxrvoR7UXrz0UmarQg= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594671; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=f220kEhJ66X+jXJtp71OpS8vD3cCaDjeBL3VruhruPw=; b=DGlUY1Nvp6J7cbqxCYsA86vy4Y8kXTpP9HkCeSTuZgv5wUcMGt086MAcZceXisZR n2c3JvBB7/lxogp0Qmt5YBEH53mRXiprExKfE0IdK11BWMQnmV21iCx4SHnHti9ViRx IK+aviaBAwliWVspCz767tqXC+PAHA2AOUcUocvI= Received: by mx.zoho.eu with SMTPS id 1773594669150432.95309967974856; Sun, 15 Mar 2026 18:11:09 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 6/7] lib/tests: add glob test cases for escapes, edge cases, and new features Date: Sun, 15 Mar 2026 17:11:03 +0000 Message-Id: <20260315171104.268944-7-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" The glob kunit test suite had no coverage for backslash escape sequences, and was missing edge cases around wildcards with empty strings, inverted ranges, unclosed brackets, and consecutive wildcards. Add test cases covering: - Backslash escapes: \*, \?, \[, \\, non-metachar after backslash, and trailing backslash matching a literal '\' character. - Wildcards matching special characters in the string (*, [, \, ?). - Wildcards with empty strings: * matches empty, ** matches empty, ? does not match empty. - Inverted (backwards) ranges: [z-a] and [9-0] now match thanks to endpoint normalization. - Single-character ranges: [a-a] matches 'a'. - Caret negation: [^a] and [^a-z] as alias for [!...]. - Unclosed bracket: [ treated as literal. - Consecutive wildcards: ***a, *?*, *?*?* patterns. Signed-off-by: Josh Law --- lib/tests/glob_kunit.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/tests/glob_kunit.c b/lib/tests/glob_kunit.c index 362b1eda8e5b..9b53060e7c8e 100644 --- a/lib/tests/glob_kunit.c +++ b/lib/tests/glob_kunit.c @@ -80,6 +80,53 @@ static const struct glob_test_case glob_test_cases[] =3D= { { .pat =3D "*bc", .str =3D "bc", .expected =3D true }, { .pat =3D "*bc", .str =3D "bbc", .expected =3D true }, { .pat =3D "*bc", .str =3D "bcbc", .expected =3D true }, + /* Backslash escape sequences */ + { .pat =3D "\\*", .str =3D "*", .expected =3D true }, + { .pat =3D "\\*", .str =3D "a", .expected =3D false }, + { .pat =3D "\\?", .str =3D "?", .expected =3D true }, + { .pat =3D "\\?", .str =3D "a", .expected =3D false }, + { .pat =3D "\\[", .str =3D "[", .expected =3D true }, + { .pat =3D "\\[", .str =3D "a", .expected =3D false }, + { .pat =3D "a\\bc", .str =3D "abc", .expected =3D true }, + { .pat =3D "\\\\", .str =3D "\\", .expected =3D true }, + { .pat =3D "\\\\", .str =3D "a", .expected =3D false }, + /* Trailing backslash (matches literal backslash) */ + { .pat =3D "a\\", .str =3D "a\\", .expected =3D true }, + { .pat =3D "a\\", .str =3D "a", .expected =3D false }, + /* Wildcards matching special characters in string */ + { .pat =3D "?", .str =3D "*", .expected =3D true }, + { .pat =3D "?", .str =3D "[", .expected =3D true }, + { .pat =3D "?", .str =3D "\\", .expected =3D true }, + { .pat =3D "?", .str =3D "?", .expected =3D true }, + /* Wildcards with empty strings */ + { .pat =3D "*", .str =3D "", .expected =3D true }, + { .pat =3D "*", .str =3D "a", .expected =3D true }, + { .pat =3D "**", .str =3D "", .expected =3D true }, + { .pat =3D "**", .str =3D "abc", .expected =3D true }, + { .pat =3D "?", .str =3D "", .expected =3D false }, + /* Inverted (backwards) ranges */ + { .pat =3D "[z-a]", .str =3D "m", .expected =3D true }, + { .pat =3D "[z-a]", .str =3D "z", .expected =3D true }, + { .pat =3D "[z-a]", .str =3D "a", .expected =3D true }, + { .pat =3D "[9-0]", .str =3D "5", .expected =3D true }, + { .pat =3D "[9-0]", .str =3D "a", .expected =3D false }, + /* Single-character range */ + { .pat =3D "[a-a]", .str =3D "a", .expected =3D true }, + { .pat =3D "[a-a]", .str =3D "b", .expected =3D false }, + /* Caret negation syntax */ + { .pat =3D "[^a]", .str =3D "b", .expected =3D true }, + { .pat =3D "[^a]", .str =3D "a", .expected =3D false }, + { .pat =3D "[^a-z]", .str =3D "0", .expected =3D true }, + { .pat =3D "[^a-z]", .str =3D "m", .expected =3D false }, + /* Unclosed bracket (treated as literal) */ + { .pat =3D "[", .str =3D "[", .expected =3D true }, + { .pat =3D "[", .str =3D "a", .expected =3D false }, + { .pat =3D "[abc", .str =3D "[abc", .expected =3D true }, + /* Consecutive wildcards */ + { .pat =3D "***a", .str =3D "a", .expected =3D true }, + { .pat =3D "*?*", .str =3D "a", .expected =3D true }, + { .pat =3D "*?*?*", .str =3D "ab", .expected =3D true }, + { .pat =3D "*?*?*", .str =3D "a", .expected =3D false }, /* Multiple asterisks (complex backtracking) */ { .pat =3D "*ac*", .str =3D "abacadaeafag", .expected =3D true }, { .pat =3D "*ac*ae*ag*", .str =3D "abacadaeafag", .expected =3D true }, --=20 2.34.1 From nobody Tue Apr 7 05:47:54 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 605ED3750BE for ; Sun, 15 Mar 2026 17:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594677; cv=pass; b=TryfbxrBdF1iKrx4Wa+UxLAmy635de5iUgzOylY3wa9QGzsRghmBGrLmMv4nd1w0yf4hroUYKkcWnBcKLC2p2vj8xeMyEgQKyNBdviRsFmsjXgTPSvpKGPPSRilVc54y7EHCvqFnbDrYfayqaUqYiXwuMFipMaeJwVVr/e56Ruc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773594677; c=relaxed/simple; bh=MrFEroHwYorqSWGBoY5ocHzyEC+JzAla+WphZ3zVa6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=prDgHCwLB8DSAaLt1B5zA+EY3GTur1fVpSsIwtWcj/Z4w0U8ycecRaIZU/KIw0xf+bXjnwtYdCLM8Wy2OFhUTYkfo2594/HwCos0iL213ZHPhT42QotpcWz78neu18J2EkrRKMsuNbeJr0fK6K3q1jyHpxPsAHnRbK+sHX9y18M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=X9x8/EQK; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="X9x8/EQK" ARC-Seal: i=1; a=rsa-sha256; t=1773594671; cv=none; d=zohomail.eu; s=zohoarc; b=WQswHqsEbA1vx3QolzeQYrgNTOfCE5kh/NdlnQ3daohdBFCNY0fjOPXoTH0yzfP4heV6ekJKj9dZkGLuwfgmt4nKC/P7/OOFhGKBZu/V3cjHdTUZoGZZyDObGv77q27AcBMwqtQ2Fg/A9lIVITGiMTdcZPyeAitz5Mxz+S8VkGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773594671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=/JtZCIPsgGracX5Mx/4hRAMi9BpwqYEGpkwpzrg8Moo=; b=i+GtGcZZv6+dgVIl7/ytk8bAAq+uq7VIXWuSBgqGV5k+GVj1Jnefe4P2MGHVtQufWjSI7IHOriY2rs5pRZHOiV9aoeRX+WpGeKhL3iG/iOUwZELkEQK5lF6KipD/ATGZSSwaDOjAW1QVtu4Q/1y6+E0CmejqKQmqldVeDzEM0kQ= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773594671; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=/JtZCIPsgGracX5Mx/4hRAMi9BpwqYEGpkwpzrg8Moo=; b=X9x8/EQKiVDc/gAvQil7HX1mpUYCw0l6XvyOX3pRaxnfnYWfvK+1T5wjlKFKX00o OyeB4+Nc5LsIcP0FhBzHhQ6u/MGNjmDNaTdXGhduxo2QXfQx0optzsCARh+sqK2n4mN AiLAEaH96ozcjxUC1ZQaa+5q9NSysZim3OzOryAo= Received: by mx.zoho.eu with SMTPS id 1773594669572303.50176239745804; Sun, 15 Mar 2026 18:11:09 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 7/7] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Date: Sun, 15 Mar 2026 17:11:04 +0000 Message-Id: <20260315171104.268944-8-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315171104.268944-1-objecting@objecting.org> References: <20260315171104.268944-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Add parameterized test cases for the new glob API functions: glob_match_nocase() tests verify case-insensitive matching for literal characters, wildcards, character class ranges, and backslash escapes -- e.g., pattern "a*c" matches string "ABC", and range [A-Z] matches lowercase 'm'. glob_validate() tests verify detection of malformed patterns: well-formed patterns (character classes, escapes, wildcards) return true, while unclosed brackets ("[abc") and trailing backslashes ("abc\") return false. Signed-off-by: Josh Law --- lib/tests/glob_kunit.c | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/lib/tests/glob_kunit.c b/lib/tests/glob_kunit.c index 9b53060e7c8e..711cb44d1fc8 100644 --- a/lib/tests/glob_kunit.c +++ b/lib/tests/glob_kunit.c @@ -157,8 +157,85 @@ static void glob_test_match(struct kunit *test) params->pat, params->str, params->expected); } =20 +/* Case-insensitive matching tests */ +static const struct glob_test_case glob_nocase_test_cases[] =3D { + { .pat =3D "abc", .str =3D "ABC", .expected =3D true }, + { .pat =3D "ABC", .str =3D "abc", .expected =3D true }, + { .pat =3D "aBc", .str =3D "AbC", .expected =3D true }, + { .pat =3D "a*c", .str =3D "ABC", .expected =3D true }, + { .pat =3D "A?C", .str =3D "abc", .expected =3D true }, + { .pat =3D "[A-Z]", .str =3D "m", .expected =3D true }, + { .pat =3D "[a-z]", .str =3D "M", .expected =3D true }, + { .pat =3D "abc", .str =3D "abd", .expected =3D false }, + { .pat =3D "ABC", .str =3D "ABD", .expected =3D false }, + { .pat =3D "a*z", .str =3D "ABZ", .expected =3D true }, + { .pat =3D "\\A", .str =3D "a", .expected =3D true }, +}; + +KUNIT_ARRAY_PARAM(glob_nocase, glob_nocase_test_cases, glob_case_to_desc); + +static void glob_test_match_nocase(struct kunit *test) +{ + const struct glob_test_case *params =3D test->param_value; + + KUNIT_EXPECT_EQ_MSG(test, + glob_match_nocase(params->pat, params->str), + params->expected, + "nocase Pattern: \"%s\", String: \"%s\", Expected: %d", + params->pat, params->str, params->expected); +} + +/* Pattern validation tests */ +struct glob_validate_case { + const char *pat; + bool expected; +}; + +static const struct glob_validate_case glob_validate_test_cases[] =3D { + { .pat =3D "abc", .expected =3D true }, + { .pat =3D "*", .expected =3D true }, + { .pat =3D "?", .expected =3D true }, + { .pat =3D "[abc]", .expected =3D true }, + { .pat =3D "[!abc]", .expected =3D true }, + { .pat =3D "[^abc]", .expected =3D true }, + { .pat =3D "[a-z]", .expected =3D true }, + { .pat =3D "[]abc]", .expected =3D true }, + { .pat =3D "\\*", .expected =3D true }, + { .pat =3D "\\\\", .expected =3D true }, + { .pat =3D "", .expected =3D true }, + /* Invalid patterns */ + { .pat =3D "[", .expected =3D false }, + { .pat =3D "[abc", .expected =3D false }, + { .pat =3D "[!abc", .expected =3D false }, + { .pat =3D "abc\\", .expected =3D false }, + { .pat =3D "\\", .expected =3D false }, + { .pat =3D "abc[def", .expected =3D false }, +}; + +static void glob_validate_case_to_desc(const struct glob_validate_case *t, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "pat:\"%s\"", t->pat); +} + +KUNIT_ARRAY_PARAM(glob_validate, glob_validate_test_cases, + glob_validate_case_to_desc); + +static void glob_test_validate(struct kunit *test) +{ + const struct glob_validate_case *params =3D test->param_value; + + KUNIT_EXPECT_EQ_MSG(test, + glob_validate(params->pat), + params->expected, + "validate Pattern: \"%s\", Expected: %d", + params->pat, params->expected); +} + static struct kunit_case glob_kunit_test_cases[] =3D { KUNIT_CASE_PARAM(glob_test_match, glob_gen_params), + KUNIT_CASE_PARAM(glob_test_match_nocase, glob_nocase_gen_params), + KUNIT_CASE_PARAM(glob_test_validate, glob_validate_gen_params), {} }; =20 --=20 2.34.1