From nobody Tue Apr 7 06:21:35 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 3B7137260D; Sun, 15 Mar 2026 20:18:47 +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=1773605928; cv=pass; b=ql8+CSvT5bPSmxpB3aFTPkVi09XyNDKMmEnzAvwGmU4uWKr5If4plV/Zg+ZS8v6op3VDROgersdgDGnFbBf/rvjD5M3eihXO0VwOxxHhqzSeW/0S79S3kc4PG+Ap3NFxyQ7AL1cCv5vurdSNh42L5C7GncWvPOypbIZOVQIRyEs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605928; c=relaxed/simple; bh=TvoodWqX4Zt9qaZn8/cmtP96TLJg6Fl3uNkMx+/OM/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GkheNPiFEI4p2smEhZ2PZgVtRPVfFfC0mnR+2zTh1eICUoMi5Q207CpoMtuMfR+oGZ0kD6EPpfX6KRDl5NHWZ2fJ51KsughkmmT7O0jNdzVtdtFYZQbYqxC3bzr/F5fg9EXSY7Ix14X2z+GZjK5vhLMrsNcbaViq5dLL4nYSZyo= 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=G9YiP62M; 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="G9YiP62M" ARC-Seal: i=1; a=rsa-sha256; t=1773605899; cv=none; d=zohomail.eu; s=zohoarc; b=iMO5rkVZil4xqap4z7PGcVxxfBRle3SMOFh7Op9OEMKgxckpOSksXOnlW4UAJgJ+evQ2HedIcj4PeFknMhQV25yhdR8QLmd0J42+lqzjiX0W6N+WQTmLrXy/TSKfVl67/WrPmvJl6NNZA041P14hvdIF5/VM/9HLKcuhSeplhb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605899; 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=Eq7DDB5T9eDeIFTpk2acAAbiNTtDkeACbZqPXH4fa4IN7bSZfmNgW9VokhzwW+CXd/7SvjiR48lC7yXHB26pRoCD+ysnxOA60vTzFkrsjjlIL8F+AFS6+CXH3QiPPfwZGUptWX7LL5+NE/zOzt22xz+MtSvqe1XiU1eLHi2iNo0= 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=1773605899; 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=G9YiP62MSDYMqlSoAR/ziqMrltcy9SZCES96/58tKOjfadJlFo5HbGUZK9p1ISgE 3NKZJSEfg5lNqglVwEsG7HN1izpjEGTx6pRQgOwkmanJxsaleSDMXDeP/bt4Io6IVwO iOaapeqE5pTHswspp5xHWxqB977ODNqVBS5dbg7w= Received: by mx.zoho.eu with SMTPS id 1773605898407517.8260685904943; Sun, 15 Mar 2026 21:18:18 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 1/8] lib/glob: normalize inverted character class ranges Date: Sun, 15 Mar 2026 20:18:09 +0000 Message-Id: <20260315201816.362559-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 06:21:35 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 1DB1C1B142D; Sun, 15 Mar 2026 20:18:35 +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=1773605917; cv=pass; b=q8n0aJDT0XpPPO7u9xqCff4heIK0vXqq8v216TsWUlOoQnmhROhklvwTGdXGoMc5ip3E8WEYneKITJjXWgLhcNfYSGy3Ld9nz9VZ8V0J8ubMmXhbicJp5tvVP8aWtIPPRGdFS22g2gdAEhuSpa5P+HrBvj5wB6LJq6jTh5esKmQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605917; c=relaxed/simple; bh=ynosWAVdTZjwHIldBKnJyOHFf6YCnzrYK/oMhyqjJmI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uMGuniaUyujwpzDgF/SDD3UDXi2eWYvDT4BbJjXHPHb1p1eLdJ0uF/3MqEq6Ou7q/5GrGNhu8o+hoFgy/6Sml9JIaddxJv4xfJe6XTXnn9SieDW37197Oq1hIrZFQyE3RpO753u+YevtxU1qndupu8lVV+1vpvUHn5DCYop76yQ= 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=hqCtVocb; 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="hqCtVocb" ARC-Seal: i=1; a=rsa-sha256; t=1773605901; cv=none; d=zohomail.eu; s=zohoarc; b=jwrvhCdloAiOwVm04ghWTPy9MlQd+hVTA2niZU+cmMG7FbrLrCDbPnRLId4AfArEZRj2UtqsK5iL2xsgrz8p+bj4RIHIzKR4OMB4yZqggW/LJsqRAJoCCe+Q6Um2jcRRBH2t1+jaOWo8abhMJVX9nVxOLl10FmkckcBeEn3Ymbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605901; 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=NQVXi0yyAmh6340zM3nLahuTAeRSrnIhN+rBi74S0l6kBdAnfKc7S8qzrZ3urEoMKOcM9qEabnrT7Y6FZl2ycs2bFQChQx8ZV36hk6Ci9NkawXl/H2tUiCFfHxKFPTXZBGXV0e5j5y8WBsORCXG8qESDosR5P6HVNXzSfiir/rg= 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=1773605901; 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=hqCtVocbGAScaNMQqVtBWiFqwYueNl790mulJ/yQs1sXsDywMZj6IMNkzffCcM00 suT6MUp/1ZkPCbeRU5f/KNjv0QsCDGJF3o8vkyFF0RaNllV64CI0aYVxOR2PoChC7U5 lneBT5Ovt+g2VvyBl1F5871eRSYyAoRSgUBtozKw= Received: by mx.zoho.eu with SMTPS id 1773605899046757.2274425986716; Sun, 15 Mar 2026 21:18:19 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 2/8] lib/glob: treat trailing backslash as literal character Date: Sun, 15 Mar 2026 20:18:10 +0000 Message-Id: <20260315201816.362559-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 06:21:35 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 58FB037B016; Sun, 15 Mar 2026 20:18:45 +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=1773605928; cv=pass; b=BekQWC4TG41A81l0ZhtAKgPRsM1AlkCh+kyUXnCY3jAA3c94yQAPIUkRC1g+AwxyJcDA1HD42BOsLlH+E5ql5ggNVCQlGG9yv6hrhBpUxQNcbdrXKwtUpVOe/5g1/h7+r0k1Xbi/vHbU2+C1OLc2mY3PrToj6jItNzIAi2YpWes= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605928; c=relaxed/simple; bh=XgWFRb8ONcA2GQ/HdeRNANjgs9ScGEr/4d+esA/Kb7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kB3RixdppOj9oaHLmKiLOnPWUe9wdsfJDz2/0nr/bC5/zTgWiucCLJfa8P8vlzczQTf03aaKsiTS31z1BGAB2NBfwto2qOh+z0gaIEt4m8hXzxNrgfT4vBTxZW1PcDVE8NFwb2zauBXTDw5RMeAe7zzuAjL+gOUmsi88TkecKMM= 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=UVrLeEDn; 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="UVrLeEDn" ARC-Seal: i=1; a=rsa-sha256; t=1773605901; cv=none; d=zohomail.eu; s=zohoarc; b=HP/3YoaJ+Asns4nltYUTozZREvMjGk5VEJTiv6DN/VCTzY79ZwLPHVpPtot1DRfeMUBj4USeXiT4l48w/bp5a4C/UCfNtUm7NUeE8QLYVJhCVNjEbf6DLsb3maV2F9z8vsFEbUfOKhpBsYrrK2ng93OdD3QapJKa6K0QlQ0yrAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605901; 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=RcrzUsV/vNQ8tsnaoWVDvXi5WifxtfekqqnVjc3W2sLPb5t33k6W3Jph5+gezH2+hWvrgiv7kFz+PJUgZgo6hkBjtiTQmWUK8sybO8nP9V4Sek/+FXLL8+sxWhvGLUjW3qLRO+HnhUvJmjEjzPhemX13apTcmlRBJvb89EoIxZg= 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=1773605901; 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=UVrLeEDnYCosB0ex4RnCPeyiyxC3nZVxuw9e1SSCRAe4T+3Gtft+yy5tmcRaV6Mj bvrpKl/2PshBNLcFs69hYP9mkoH5qoNlbnhyOwNyqDIRDBBFAGCyS8LCI2RkcFvq7uX yPC5kq3u1sFNWibdy4ex+AKDXTDWygONSstVSdE8= Received: by mx.zoho.eu with SMTPS id 1773605899686143.73605095344908; Sun, 15 Mar 2026 21:18:19 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 3/8] lib/glob: accept [^...] as character class negation syntax Date: Sun, 15 Mar 2026 20:18:11 +0000 Message-Id: <20260315201816.362559-4-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 06:21:35 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 396A437AA88; Sun, 15 Mar 2026 20:18:46 +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=1773605928; cv=pass; b=L32+YvQdYwGFBeeVQ7pc+Y1uF3uRlB9EG39PnBarzMKcxEPC3RDIxYqPvTYnFzqqD5g6agsSGGmLK5wjzUORbZixQZTEUUn3/ZwQq7VUJCyS3rh7thPDzhriEM6MgLayjYU3J05PG3GSgjeQ3Q165/gTrLs7fRrCo66034EJc5Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605928; c=relaxed/simple; bh=POeuv5ojK94O2H++yVuXxLI5I7CW0YJOM4PIKL2jne4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sv0s/7m7UZ6ffxBtCAEI9izsnsSmyB/mNcLHNn4rlHi1wMQb+ase7j51D6McllihxhqVymgMl4CS28IOYv1D4+rfIusFdQXW/JMj82n8d3xOgZqXEJL6w9FwrLoQm+2LY4p7qPwIRQdrk+oRgaYwkurZ4neKex9ibh8VspbF50M= 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=knw5ysLv; 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="knw5ysLv" ARC-Seal: i=1; a=rsa-sha256; t=1773605901; cv=none; d=zohomail.eu; s=zohoarc; b=T6EkKpS1aqTEH3NgP7HMQejNp/n4QIM+rAVmeSe3sZ+2PcM4Q26IvEQpRZ1M9vYKG+d+dPbE0fR5wvuOHQKNuTeAsyZGoM4eQtkMJMXbYg9Hmnp01q/jlf8J+/5AKQTtSigAreBu3tufnQajpJo65nc33xDnhwqt78NiB1zpIb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605901; 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=KiXJHWYlNASgwx5Dzu2oYmEDoJbAXIYgByl3vF7pLEc=; b=gi+X5sCEPXXotL0rcJQ8c7mEbOj8YewOLQ0Quk8Sa4pvKID6L9StWeHXyxQC5SRsz/SOfEgh22RXt8wgwZ2ZGqAta8cSR4WJQDIKhuPXsjB7fYbQwcYkNk1qdGOPomvwIKYc+8Jjb+DDGyG2cPQK9D/U6pIzxAV0PCELWdb2koI= 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=1773605901; 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=KiXJHWYlNASgwx5Dzu2oYmEDoJbAXIYgByl3vF7pLEc=; b=knw5ysLv9QnB9OPPfMBpcH7LZZiE/cPj1SB8uYoZqj3FQrMVwP/athq/qu7MXBgm JrEwayT9+4CQn4Av3E3UTnHqZDiRKX9JwdqiGeSKZ4v3bprSNewWobNegT8cFErYPla 6zywRcmYDkeGVOlKXxr1NZMWHh7J8UohYmQzJUlw= Received: by mx.zoho.eu with SMTPS id 17736059003251012.471441025747; Sun, 15 Mar 2026 21:18:20 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 4/8] lib/glob: add case-insensitive glob_match_nocase() Date: Sun, 15 Mar 2026 20:18:12 +0000 Message-Id: <20260315201816.362559-5-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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. The immediate motivation is the ATA device quirk denylist in drivers/ata/libata-core.c, which uses glob_match() to match drive model and firmware revision strings. ATA IDENTIFY DEVICE data is space-padded ASCII and the specification does not mandate a particular case, so a denylist entry could miss a drive that reports its model string in unexpected casing. Switching the denylist to glob_match_nocase() (in a follow-up ATA patch) would make it robust against such variation. 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 06:21:35 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 9E55437B016; Sun, 15 Mar 2026 20:18:39 +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=1773605921; cv=pass; b=ecy78ecHsH+rzd72HG8I2NCdrKJagole8y11QSgH0SoHnoHr/kzKdZe6/TPZqp55KgfMXih3/N9M2cOqS/i0THdaMmKBl42baOHDdzteFPzfmOWdIo+VYI2X8xnxqcIymDSoGYB758AmtZuMMzJU0pYEhP/wmtFtZb+6Osi6OBc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605921; c=relaxed/simple; bh=MPc6BFCGSACM368hqh07vzRexP5rxqkSUbTOB1V8GJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EKGqhnhfbX1+VWAAjHrjuAKL5lAJ9ZRwdwz3TwWyjYTmcnJqN0upr1KxyaCCthoA9cEEBIPVIZXdvXhoG/k46xue/JeO1BK8+x40xj3a7RaOebHKDyxXWO1djiu5j2hFXSoEer/yclx2dsPNznau6YCUAX9aOKD4oyCBy0xb2D0= 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=UU/QDsVx; 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="UU/QDsVx" ARC-Seal: i=1; a=rsa-sha256; t=1773605903; cv=none; d=zohomail.eu; s=zohoarc; b=lHTeTi0WN+nWDz3fVfuNwSJimy9fl+bbjaOforw1vf/RggTWwTm7BLc0bvlZfp63406OiBoF4k1+QwqXI/ZYX1rSmOACTE9qan6qcUzDSQvp51NGT+4hDMiWxevdU1Zoxhz8m0IOqzDoT2vLc1aiQP1lOVBJlVkhgMfAhyGI40Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605903; 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=YIosLydX5M3FgZ/jzUx4rPARfV0eCD2Aou5ZSJjUMyAMe7ZrA9Cn8vkfDJ374AW6GcPyCI19ym2YZBi0HobnzxizUsuIz8pct2wDRGgklPhfgO8kMEaskvLV6gDmLVUFvs00+e2mdAmO7ffKc8BTi5o4lR7DlAt4PMhb+Jukmfk= 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=1773605903; 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=UU/QDsVxwBNu3lB/AZjbs4b/UYzhhukJvAp1hZqeJfHXnKxGYF1r6tzzpOcEGjwy pxTXFwfj5OLQP+LaRAZ4m+wyY0VSFR3/I/WXbqiCfeAWMUKeETuJYwyTt500+wDpwxb 4c+FKjb4NFF0zQrT2oZwm65QUEUvgDvZBHaOgRcI= Received: by mx.zoho.eu with SMTPS id 1773605901032232.15027274943418; Sun, 15 Mar 2026 21:18:21 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 5/8] lib/glob: add glob_validate() for pattern syntax checking Date: Sun, 15 Mar 2026 20:18:13 +0000 Message-Id: <20260315201816.362559-6-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 06:21:35 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 DD21B37BE83; Sun, 15 Mar 2026 20:18:37 +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=1773605919; cv=pass; b=UTPJk2r9dlpDM7J3TCYoFjCZT9PfLE2E/uMmorR4p+qiGABLk0LrVYeeCq0PELTnV5nqx0FLYxKJIFNfpcXsPm6nUStUSH0cPk/KP0AOHAE0+YluBGYPvR9gbKunfaGCOcfVxX0MQ9Hhl4ACwSDAxtj/20331ZRNUQUTPcpIbCE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605919; c=relaxed/simple; bh=DqDIHMd4MJlmLaUnm4FNNfD7TmiR4u66qXh4CXNuOwo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nDMVefINPAnmyn6cy2hgpc2xIvEj5feYD1sfi4aJ7ydfbdDHYvwo90VYSprkVdeK9yQsWBpSJmfYIOdGjCfWg3pl8TvIc9k6yoD0fLv4B5v2xAGI0JeL45EQe/rH3wbtU+ALlOdWSoCcO25f6sRNOq4Q0HjvVuKn8pC8hs9cV7A= 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=abE7v3nC; 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="abE7v3nC" ARC-Seal: i=1; a=rsa-sha256; t=1773605903; cv=none; d=zohomail.eu; s=zohoarc; b=hEayP/4Ges+ZsRbkOMpqyi2t82z8yC5HcOOu2nlJlNH5mGo5BaMGBDNTHB1W1MLmkqUo0kE2NyHEYaHRK94oWQ8lSj1XuTWjNFjVuiCQ3uxc5aTswONGFEQd+xexbwQZb/oOsGYB4N+5lyPiG+DB7jnziZlX/VlN/ansV1ywa5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605903; 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=OLoPSBJ23fnv+HEcjrtvcRhZx4lS7gb2IfbLMiDdlT5nsIMDUlsTt+UQPLyiBrU1ikZxd0Ih9pfnfeUAmTdu/NszIaY26Ajv0n/0auVfS0EQRiBk/T1vkumWqyF4PrExIQzyCJ8fMdDI1XilR/unXI9ktAEED8Y6eVonKgWquL8= 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=1773605903; 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=abE7v3nCZdcrIfpZKSa0Bl15NIpuG8cWtQdEWenBko7x86BJlfkd6vATdFs9nJCU +VupqZEaWaKzrsSltTcyXznOyz2LEdc03MBzLp+v6+4Bn6hPlI3Icx+XIEotMWdnIxW EvP/rWjoqJKQhkiCTJvT6B9siYxDEHAQbqiuaVCc= Received: by mx.zoho.eu with SMTPS id 1773605901733664.9290395481537; Sun, 15 Mar 2026 21:18:21 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 6/8] lib/tests: add glob test cases for escapes, edge cases, and new features Date: Sun, 15 Mar 2026 20:18:14 +0000 Message-Id: <20260315201816.362559-7-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 06:21:35 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 8445F7260D; Sun, 15 Mar 2026 20:18:34 +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=1773605916; cv=pass; b=PvOS6rH27TYY2sfEgFRh+x5zXo8zFTEHIITRJ3YmjunjrNN9DT2zJGrNaZACWCXd1gwOIEaJwi2kLO5qG7dYkzYOIak02EX01/PBisxOrzBZtXUiwCh2Wp4w1CEUGvOH+np6lMYLyBbZqKqYzW2prgWqMrZ8I8j9QUkcd4U1OE4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605916; c=relaxed/simple; bh=MrFEroHwYorqSWGBoY5ocHzyEC+JzAla+WphZ3zVa6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EEIPdkz1UmWLlDkkzidHbaZ5WS49tBGTA9MBpWWYeNahsrn3aishReLFDRMmhgq01T6v5Pnc8uiqslQdDRCnFd7vbC8O4wVIBtLw23niWrFiQFM5WVUUY6BBeUC1DkEk3bA/xlG6XzBGE2st4R687GFKDaI61KgKjd5yzUHdKLo= 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=dZh0iXAB; 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="dZh0iXAB" ARC-Seal: i=1; a=rsa-sha256; t=1773605903; cv=none; d=zohomail.eu; s=zohoarc; b=UYm/7haN5gHtv4cBD9P/eDDClYOxQEHWDSE0cKqiimtA+jouti3PeRKZFTlgPxoIiGs/10zU54dcGaweFKGZSuR9gwZ5QAYcuwGv30oIZh3kr5/QkITYFGtXBgld1L+LMzRct8Ged3TkxhbHJfZGt2YGkV7Lel4LAdjJzo37Kyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605903; 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=CiSLmASxo7UUQn5X9qAIA/3KoYgO44HCeuTV8pjV8YxX2UIRJEA/uF/fiuqme1lzkfwakbPQgsHhFwzG5OW5c08WcQEEIexMuxPT89wQerkm4/7k25wfDOXquCTJvDZLIpLLrusQYQgEkguCeTaZ5OGQxl7R8mIuGbZBmypSqOc= 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=1773605903; 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=dZh0iXABFMJee1F9mSGEGmZDwmQC/Dbq+mgqadUip8okd31KccfJjMd1cyOKkF3n Lv+3tgA3FyPcmg1+jcgCkxSfokw51oC5ReS5tMYC/GKyDWJwRiTatxLvP3q4XiZp6aF 6GErnK3jt6svDcuw220ym7qtOws2A0QoRcYXm/FM= Received: by mx.zoho.eu with SMTPS id 1773605902397573.3245035504432; Sun, 15 Mar 2026 21:18:22 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 7/8] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Date: Sun, 15 Mar 2026 20:18:15 +0000 Message-Id: <20260315201816.362559-8-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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 From nobody Tue Apr 7 06:21:35 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 DDA8137BE8D; Sun, 15 Mar 2026 20:18:39 +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=1773605927; cv=pass; b=gCfIPW4BusArP+GXaIf5e+JYLc6JSE9GwW8npdccku8uAg7tbeOg7D5sJtBMxk9FqrcSD//yb5mX7910oX4PCg3bz5cU/Qm8ZwHVFi/3uSMK5uKrYaXiMdlP2EQaSFVrfRXxYqzkWympcrZTHqg193OgcGENwVnjT1Ca1dJznDg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773605927; c=relaxed/simple; bh=nDNdIz9w1v6GX9HKPOLSEpcSx9VPTmDZ0uZ7Lf2JPJQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Lqg7/mCft83MMX5EZxtO/UeiMoo7tzWzyL1+4a4LbZm4Nb0IGFwJpoBLS2BGWbqWJp8A1bR9BPURetDmw9mEtv/60U5lS7mlA0i2Pan107ptMXz4e2GvQ3DVZMxzBLuOBE2DPlSRz87Z8IdUaiU8gs/NcLNQp//Hu1vstaFbdnU= 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=hVbAphBK; 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="hVbAphBK" ARC-Seal: i=1; a=rsa-sha256; t=1773605905; cv=none; d=zohomail.eu; s=zohoarc; b=gS0JqNsZ5Wp0G1oNtIrWYd0RqfhRhA9e8ZEsqdujJ3EArdl/geopXwzZOnlBaelGcIIOi4VAV+uqbnfiXPGVlfRCkHkHNyihUwbgWxoutwQl8UYnbuSNoo1iWk2STFgoB4Nz+x596DCb+0kFzkeCJdd5n4gpOvxFSCID/fgu0gU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773605905; h=Content-Type: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=x5o3NZywWI/GlA27vRpItmX4VibMyB/hLnI+Hl7u6to=; b=YeA+u9XuDqq6vqLMHxAVTSYj0h3X8YdnXe3IS3OLOIskGGy4KX7dnFIs32JuAE2Sisee3zZCzbrNfodmPqRppBZ0MW3hC327boAWNQovio7u3WuDn1qJ6eB9vm/itlBdZ5NtC8nu15zsH/B8A1Q+W368eNzkv1DagxkxSyFhdlg= 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=1773605905; 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-Type:Content-Transfer-Encoding:Reply-To; bh=x5o3NZywWI/GlA27vRpItmX4VibMyB/hLnI+Hl7u6to=; b=hVbAphBKXsZqcMy4KjzS3AUQ3b04q3AeyQVYS8y1oKQA06QCebMuuFst6wstTMQM por6JHJHGzRZtVB9JrpYTNqE65NoyOcJ5Jdy7jX9QRjkA8ZsTw+peL2d9COiSZUft7a WrOrJeqrQYMajFpVk4aYmU81naGP+ggE94fyxtpw= Received: by mx.zoho.eu with SMTPS id 1773605903081814.8605519676821; Sun, 15 Mar 2026 21:18:23 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Josh Law Subject: [PATCH v2 8/8] kunit: validate glob filter patterns before use Date: Sun, 15 Mar 2026 20:18:16 +0000 Message-Id: <20260315201816.362559-9-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315201816.362559-1-objecting@objecting.org> References: <20260315201816.362559-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External kunit_parse_glob_filter() accepts user-provided glob patterns via the filter_glob module parameter but does not check whether they are well-formed. A malformed pattern like "suite[.test" (unclosed bracket) or "suite\" (trailing backslash) is silently passed to glob_match() which handles it gracefully but not in the way the user likely intended =E2=80=94 the bracket is matched as a literal character rather than startin= g a character class. Use glob_validate() to reject malformed patterns early with -EINVAL, so users get a clear error instead of silently wrong filter results. Signed-off-by: Josh Law --- lib/kunit/executor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 1fef217de11d..f0cc15e4b34d 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -91,6 +91,8 @@ static int kunit_parse_glob_filter(struct kunit_glob_filt= er *parsed, const char *period =3D strchr(filter_glob, '.'); =20 if (!period) { + if (!glob_validate(filter_glob)) + return -EINVAL; parsed->suite_glob =3D kstrdup(filter_glob, GFP_KERNEL); if (!parsed->suite_glob) return -ENOMEM; @@ -102,12 +104,23 @@ static int kunit_parse_glob_filter(struct kunit_glob_= filter *parsed, if (!parsed->suite_glob) return -ENOMEM; =20 + if (!glob_validate(parsed->suite_glob)) { + kfree(parsed->suite_glob); + return -EINVAL; + } + parsed->test_glob =3D kstrdup(period + 1, GFP_KERNEL); if (!parsed->test_glob) { kfree(parsed->suite_glob); return -ENOMEM; } =20 + if (!glob_validate(parsed->test_glob)) { + kfree(parsed->test_glob); + kfree(parsed->suite_glob); + return -EINVAL; + } + return 0; } =20 --=20 2.34.1