From nobody Thu Apr 9 10:29:04 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 94C8737C91B; Sun, 15 Mar 2026 21:18:22 +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=1773609506; cv=pass; b=ZcVp+myt89OOE9c7TINScWmdQgKucOYdXJps6sOQhT8N81lLQyoPnawOwbR6XDyNx0B1loB1WoqdKX+h7IqTmTWaaNQZtbK6kXXLrVCCJBtGoZJ3NP8YVYGxfgSdsQHfIJ6pNe1IaGzL4REI9QLbznZmoKYVxoRr7fNPFMsgrM4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609506; c=relaxed/simple; bh=TvoodWqX4Zt9qaZn8/cmtP96TLJg6Fl3uNkMx+/OM/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P0yLiXqYiEy3bc73K6AtugDsT5mt7vXbdAWv5E5CfQ7CKfY2HIyUwCTmgVNNzJX/vHaFqZ7x2mRyaIcxymWFAoxT9aLN6D+z5Hw3UZWNaaNoo/5UigKvb3x+N8HF0evV+XdFi4NlhbfbcWx4JqFZcbb9u1DoxlCXy7t8COqUAJg= 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=AgzFNifG; 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="AgzFNifG" ARC-Seal: i=1; a=rsa-sha256; t=1773609492; cv=none; d=zohomail.eu; s=zohoarc; b=JH2QV2+2tcbhefrcjvhF8EKq6bja82PNdSM5r5YyLMe/YX4O+vgpcZ0eU0K4B0XTDYAKijAG/jlMyQzWk5ve0sZ7Qd98wnAxfqmO4QZqnqzCUE9HQoZEMpzxQ/77vXXfMkTBnlj3JXAw4HFb7Lot4bEDGi+0l65Is037WsgeLRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609492; 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=Nq0cWZ1GeXglfN4nMjMn+qda85lIGWIs7rjQq/yR8tW3ywp/3G5P7bom4h1Dia8snHvzAiJNX2n523RMqkJiX52sH0svgILOh7DlwRe/BURYeWzmKPyPx51WY0BLWgEaqV+xAnq69WRB/T9N+oBVALNx/LIZe6vno/+gasMRRJE= 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=1773609492; 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=AgzFNifGd6vGVqNDdpTgmh5TAfb/36LAaAQoj0gYqal1y2pkOkk3xwTGCltD8/EZ JZlszpqXYxYKlU24vcOU+X9dv1GFIdPxJGf/8EaiOsOBDfz+mAMU+Wq3nngwhfzpKWi AnPTTtjIvn4rAjEZPc4boA1jYF4MawqDKTNVkzxs= Received: by mx.zoho.eu with SMTPS id 177360949036224.816485491883782; Sun, 15 Mar 2026 22:18:10 +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 v4 1/8] lib/glob: normalize inverted character class ranges Date: Sun, 15 Mar 2026 21:18:00 +0000 Message-Id: <20260315211807.411173-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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 Thu Apr 9 10:29:04 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 4BC0437C905; Sun, 15 Mar 2026 21:18:22 +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=1773609506; cv=pass; b=hBYBGgF+1g0ABMhPmoHkhZ4Wz+2nNatN1J3VQZJpUvH7ieoWDs856cotpoKsM5UaGQlp660dZakMWL7Yn5ZifqpLdCDuIIF0nfzPsg/0Jnp5rhaT9WJF5wHqN4XQc1LRzf1WdNimbNgagdtbG1AKYtAJxymr8qP4v3YRn/CLmyY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609506; c=relaxed/simple; bh=ynosWAVdTZjwHIldBKnJyOHFf6YCnzrYK/oMhyqjJmI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iylygffwPn5vQc9BYosiZUskB2E30NCd9udvOYuT1CqZrzVt+7dzDtnE9uNsHrdt/4B2GPM0wAx5NQMqAllkgJDXXveytzuKZGL/j+JltFY7t+DfuCTVT6I8RmM4a+lnwCDh0sXbYqZJ3Zf0V7qXiT5hkZaVEnn/yZgLqoMtpPM= 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=MO0+nxCC; 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="MO0+nxCC" ARC-Seal: i=1; a=rsa-sha256; t=1773609494; cv=none; d=zohomail.eu; s=zohoarc; b=bqAhOLkT7Icvu2QqavJL/iw51LDrPG14Z0VNsGbSIf4DSGfJmOWPe+YlrEbOIx+T8Qp6IRGv6VvV2ZpyOeV/IVpT4spAaNMi5Hki1bE1jV7BlxjljTqBDHhX9+0GULgUKgHe7/qPib2mOa4C7UXiF5Gn6EU/WPm7xu4FLQBD/O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609494; 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=eDWt1RpSLmHMpK2Nb3O4KrJt1cPoMvxUZStfGXgTqhVIFXMLplWiFi/0O+nJvzFBjerCCQJv5dezFK4r4/naljbR/m/hRGIvPPORyzeitC5BUQCDRgLhjAmy0IhWBmOmLwDaMZ26C3WeLSJarPzi5gpYav4d5edngE5Mg16O6s0= 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=1773609494; 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=MO0+nxCCxDRN7R4yk/FiIJmKg9RdmoSlVXwHHCsTj52M3MTdmDlASLU4e4kjFvZh hhYb6V3ATWUBFLA54Xp9qFiPcM0Tq7cqvSRtvY5T1HsrHXd0qYk+igzzA44ug/ohn6o HpQa9ikS7runi6O7gnGGObNvcGWngDPnf2T+mbAw= Received: by mx.zoho.eu with SMTPS id 17736094910331006.6615326755374; Sun, 15 Mar 2026 22:18:11 +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 v4 2/8] lib/glob: treat trailing backslash as literal character Date: Sun, 15 Mar 2026 21:18:01 +0000 Message-Id: <20260315211807.411173-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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 Thu Apr 9 10:29:04 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 B0F9A373BEB; Sun, 15 Mar 2026 21:18:22 +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=1773609506; cv=pass; b=hSF+T7P2oYbqtoRl4HeAYRwHlc2BiC3CXV0Yar910TU6yprfHsn4qBf7PXoa8Nhbbv+LtzZUVJ81MqNwG9F9HUgIaFw78CiZ/spMgcIzcW3UqhtH2zfoBD7l1mRwQz7R5NjN3fZl/HYUyVnwYoLca2UsqgzAGFxdXlc1xC3m1Aw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609506; c=relaxed/simple; bh=XgWFRb8ONcA2GQ/HdeRNANjgs9ScGEr/4d+esA/Kb7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TPuBm1+FSYEP7RBixgrI6gCJyFTJtr3D/+U52hy0lZfaFgZXTbecYgdPvFM0Oo4uL4a2nAxokhb3BOvWf1T3JfScMHuaFULBOIFLcz26NIxVt1P3eGJxcj0wiVrQA7uJX8Ku2ch4psfAqlY0ebFRKQRU9js1mlLgMEoXpHxTRjg= 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=jdCDk1lB; 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="jdCDk1lB" ARC-Seal: i=1; a=rsa-sha256; t=1773609493; cv=none; d=zohomail.eu; s=zohoarc; b=DLtvF2vFWhYz53H9UYF8pqTcKohZnSju1MW4OT+9y5+ltug8OyEAbkxMd3ziq/kOJEn+bMrgksyHEQXYUO5orhKZHOMS9qLg2iPa+Ch2ZEjKSu5SNAw49t91ePg4wLbqwTkzhHdScd49zmEAP3Lsr2G/RC3Yl8NwnZ2fjJ4c6kc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609493; 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=PzlSo2Dv4fbYyDZJga9pTeiWiTPxnPsrKW4dlGByMvntKOWyVTAmQn9ZK/g7/NLvNsbeCF3QWPvsSEMVERmX0jzDyTaQoRqk0wuf6P5FbaltwIcZM+Zqt/DvSqQrfC9usG/lLVje2FN12dvMU71Tpq2lJ9zHj1rAQuftOEMli6o= 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=1773609493; 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=jdCDk1lB3MsXmV6fKfBRgrLS5GN7h6uHaPDXn7vpv3/P7NqoOS5O+lqQhhrapB1u B0n8rhpCE9zBohZ4rAQDtCrjyrRewAmwlEuyfNLTqGm3s86AfGUicfXPISj7O1u29Sz 696srY95JhwU83K5Q5BeE2YQ6YeP4krqsQa/NjSE= Received: by mx.zoho.eu with SMTPS id 1773609491700998.1132090256842; Sun, 15 Mar 2026 22:18:11 +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 v4 3/8] lib/glob: accept [^...] as character class negation syntax Date: Sun, 15 Mar 2026 21:18:02 +0000 Message-Id: <20260315211807.411173-4-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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 Thu Apr 9 10:29:04 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 9C9DF37C920; Sun, 15 Mar 2026 21:18:22 +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=1773609507; cv=pass; b=HyeTFUI+LLSD+WocN+oKjfxT5aZ9MLzpyHQkpd0aVzWNhzLxFiXXTm6h7A4aBjxLMb8NkjcskqAdFowrCNifL3TrbOIQ+yAesKKWAVQfOyqC1i5MQTKRG+8xrZSy0X9s1CyT9ZrL7lP1GG0xHWoQVFogj10XTAk2Oe3+qrvgUo0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609507; c=relaxed/simple; bh=polKK+TVvNhEByk+/eHx32xRBSbjq2Xd9H4Z2XJ6PcI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e0h2CvayS8nPE4sZvN+DImFE6WYjPBqHyLuM2XIWnnaOwe9cauMAxyzQ8FxFg7TCQBdzMICX9iHmcQmlcaK2ZNdlEXGp/ZtLPu3ZyH23KLiEUX5PQyodXS2fExNTx6ef4zMU5kKBnKQXdlDQtLv06JptuN7xo12JMp612HOzCKo= 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=Y98vIZjT; 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="Y98vIZjT" ARC-Seal: i=1; a=rsa-sha256; t=1773609494; cv=none; d=zohomail.eu; s=zohoarc; b=BvJ6yOlYDgNO3zeIM2chsB7nzpAwiSyiT/w2I+76ujTnT8ylGOkAaJAFV8wQhbgOCDtmE1thXsGIPtmMWU5Qm0YlFscmavNcCJWOsd+omWENadZg/YgpevyOUknpWABqX7z4XFAH4IA/j97Ark7K3rI8BZsMKldnoNwebEJVWeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609494; 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=wV6NoXecECb7bqi4ET6OkCEvhdV779F9FKJzjGTMHkA=; b=IDswRES/at3jalH8lQ+wXABIikpFnlNH7Qv/JI70N0HnT5Q8anzh66iSIQIjYOFVnAJ5sGr0XSEutEUhcM1KgXQZs82PjeZVVCOqtX5G0UVITvQFY7heUPszO3DdsYg+vXQzGGvXZfXHqL29ZMzWLoYNKpeVd5IURugpj/Vvhy0= 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=1773609494; 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=wV6NoXecECb7bqi4ET6OkCEvhdV779F9FKJzjGTMHkA=; b=Y98vIZjTzU3mRfTdXOnRPlD9jlqnclcepGoGc8xonZjGnSQDAo21w/G2Qt2F8WDz CTf7JxwBSNh7ztqcg6NxGcos/CrH1xs23qcm8+mnK+DI8+5e2+Mkw2652BwV6wted1R rgAdY7nWTBS5rUTcghMfAbcK3Fnj6J4wEsnXEtUo= Received: by mx.zoho.eu with SMTPS id 1773609492396512.9211026066324; Sun, 15 Mar 2026 22:18:12 +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 v4 4/8] lib/glob: add case-insensitive glob_match_nocase() Date: Sun, 15 Mar 2026 21:18:03 +0000 Message-Id: <20260315211807.411173-5-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-by: Josh Law --- include/linux/glob.h | 1 + lib/glob.c | 75 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 11 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..172b8ba3cd8e 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. * @@ -20,7 +21,7 @@ MODULE_LICENSE("Dual MIT/GPL"); * succeeds, or false (0) if it fails. Equivalent to !fnmatch(@pat, @str,= 0). * * Pattern metacharacters are ?, *, [ and \. - * (And, inside character classes, !, - and ].) + * (And, inside character classes, !, ^ - and ].) * * This is a small and simple implementation intended for device denylists * where a string is matched against a number of patterns. Thus, it @@ -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 Thu Apr 9 10:29:04 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 021A037C935; Sun, 15 Mar 2026 21:18:24 +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=1773609509; cv=pass; b=fHN44APsxfBEWw7ahYNQ+IhuwaYaXIpmf66qOjmByP8zUzcmIsMOFm/X48RqaGYW/n3dEj39RQVEfXWh/SmxCv86mdy5Wt84jxXcNJgwTkdAo4J95nBY4LUwUtojQ7sE8i9PW8RNCCnHGJJj14Js9T1kbihCl3DdcXNPsEvLPk4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609509; c=relaxed/simple; bh=NK8NcdJxCO2LV2WJNqfKBaNOOeGuUndAUUlIXnyHtxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Or333EtE14bncgX6hzEsr59Bgj7ydX5VnswMfFuQBu7y29CyMCKzZu9Ups+n7OeHjOGM305q5eMKM2DRfa7EkWUX3u1c2x1/23X9SXSLz//iX5YmiLo+/YKZLqBvFUXZsasABRC7d3wWGtAi/DiP/+CBWxuU6F9Vrw8DeEzT/yE= 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=CILVSGnW; 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="CILVSGnW" ARC-Seal: i=1; a=rsa-sha256; t=1773609494; cv=none; d=zohomail.eu; s=zohoarc; b=j9/v+5bua3+bhcBOQTQ2VVeMdGwIgxR07xdEGeU5dPzL35KFTP6otf3+qYYtNY7xDGsIhRLXd515nMCJ5wmexfRuoK2UQI/jJBDRbytBpwfa/+5gxMzU3JbtAAILDaNFktJtnBizr+czSu8kspauroz6TWGIvw9PTubb4+zA3W0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609494; 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=ZH0GCSbT5tKftFXXPeA2gjcQUx1mgWMeocoKefb8MuM=; b=b0WcXK1a2PYxC7t1IbQbKXFBi2EALNHeGL8bU1KURmJrUlahzFbjaPQ91sUR4Gj0GRy5eWSQ7aMSZ+h+R22mymANBhVXy/bJZ9m4WysGVwjmUqfiicBru8V8W8o/tts33uzrq9SlgITZwtgIWUXoxBAfhETgsCtjRMqh4ksN5jw= 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=1773609494; 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=ZH0GCSbT5tKftFXXPeA2gjcQUx1mgWMeocoKefb8MuM=; b=CILVSGnWPEvRdYjboZp+cAJpoZupJxfEHFvmHNFga75YCg6O1KyLyPAYTlrCC+Em NpLPoqFNmz8gK0NQOE6+f8Q4Pel/DyoB7l4gYphIUrx1MIF/GK7xCg12jTQhLF1WYzj KkFWk1vnFRuegMOkBZ3JNNGZkbWjLEqBPsT4QhAE= Received: by mx.zoho.eu with SMTPS id 1773609493106193.04598114097564; Sun, 15 Mar 2026 22:18:13 +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 v4 5/8] lib/glob: add glob_validate() for pattern syntax checking Date: Sun, 15 Mar 2026 21:18:04 +0000 Message-Id: <20260315211807.411173-6-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 that accept patterns from userspace may want to reject malformed input upfront with a clear error rather than silently falling back to literal matching. For example, the kunit executor accepts a filter_glob module parameter to select which tests to run. A user who types "snd_*.[codec_test" (forgetting the closing bracket) would currently see the '[' matched literally instead of starting a character class, producing silently wrong filter results. With glob_validate(), the executor can reject the pattern early and report -EINVAL, as done in the following patch. Signed-off-by: Josh Law Acked-by: David Gow Tested-by: David Gow Tested-by: Josh Law --- include/linux/glob.h | 1 + lib/glob.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 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 172b8ba3cd8e..8ee539d19cc4 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -186,3 +186,46 @@ 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 Thu Apr 9 10:29:04 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 6234D37C908; Sun, 15 Mar 2026 21:18:23 +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=1773609508; cv=pass; b=FJjywSN3FBBk3s1iu6Kb2dZTR4yqkr+1tAURQ2nZOXseUHoAmqmJ9+RlI3Csy3Y171wxxoZ1JAuiOjb1jD7oGYviDVq4gX6Dy+KaMmQkiAjg03x2uelYLboTTCn4JlmOB5l97e/EozZtMUp+SstVwPwthSDILnz6xdEdg0Mp1A4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609508; c=relaxed/simple; bh=DqDIHMd4MJlmLaUnm4FNNfD7TmiR4u66qXh4CXNuOwo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jz8QViHvjqpBP0epFZldrSB88zxK2NvEd4Y2yTXXcz7S8lLKFrqKKtxKo6ME81tlJwhDhwH0NZS1txyixFYXNiNgzKm+1uPYJZEer4bBzpmCZdvZcMlH6dtYTQEXGA1R5GWTXKMCJaNToMRH/yu+E9uvC/mOAsHhImR19k7mZ1k= 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=XvIkRywz; 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="XvIkRywz" ARC-Seal: i=1; a=rsa-sha256; t=1773609496; cv=none; d=zohomail.eu; s=zohoarc; b=ZA3mFc+liYLoDZFils765SOI/rr2Ago1M/TaeZacVvJLxRMHs07F2FfJg41pi2vM9pDr3k0fs8jZDQIjT05gy22ImqKFOlYL4+O3MpkyvTb0rRRvbzFNqyXLQ46kAI3JcnCGwvShhWZfWDSUNNoXB+/J+Ix5Y0gBi0kdCOV1w4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609496; 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=OHgocSrrz+2YzKRRXX06baAA8a2yRsLF6IcwOFZdzOo17BxlIYJ0bWYdwrNDgPtHqeYacMEdVMu77Hh+m6JviC/qmkR3W/JywCYsMPaMiTl1kl5Y9OSRAmdEYcp6eNzoZzQZmPTStNV/DDcvPAwk49mWYQ2iUe6tC8P6fEKloUo= 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=1773609496; 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=XvIkRywzvL6c9Vaxp3u/1dtTiFhptcEnf1a0n/1lAISOFzs8ycb5NVsLUmmrskSm RROWvFN3NEPBhN002lJFIhNQ6j2Lk5QLa47cjhDxz21mai918t+rVOB6UpYNYO7O0Bd KrTXHtON+0J5rKc/nrgos7XiJMb68+E1Qet5X9Dw= Received: by mx.zoho.eu with SMTPS id 1773609493804233.7687287693551; Sun, 15 Mar 2026 22:18:13 +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 v4 6/8] lib/tests: add glob test cases for escapes, edge cases, and new features Date: Sun, 15 Mar 2026 21:18:05 +0000 Message-Id: <20260315211807.411173-7-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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 Thu Apr 9 10:29:04 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 531D437C939; Sun, 15 Mar 2026 21:18:24 +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=1773609509; cv=pass; b=AmXAeMEbfyqU8UrvFqkVMbfRbDfT1ev3jN1CTWhdmvVIOrTM9rcvJetbc/0UgC9E7w3Z2AGKvpJ9CRjFa/f7vVbT5c/HECwcza9bodHmwId8kXxJJQMwxwbprZ9cC0O3/BAjQSOkWJj7ciaJfsPJeUxP1u1HPgyaeP1s3HCzyo0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609509; c=relaxed/simple; bh=MrFEroHwYorqSWGBoY5ocHzyEC+JzAla+WphZ3zVa6Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LRZICogfvNLf1GFC3TClZpgp5NqmGx4+QqyFA2OzvsELloAaqM1XDV2hj3m29qVs5reCqbIo7mZSuEzIDKEBXWHuQg/h2yJuq/V0FgzHQMoRSqqYDM86DyOhdUGzycN2PVEte1GWdrB0GdspgVq7NPLfcsHnb4DNBHt9quHt6ck= 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=A+FHKzaP; 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="A+FHKzaP" ARC-Seal: i=1; a=rsa-sha256; t=1773609495; cv=none; d=zohomail.eu; s=zohoarc; b=LXSDq398A/5aYtmwFr9ymG457T2fs4BtNeoVAHjTSTGXLXoerCemQBfbHzO+szA68X90e5Pag6HeZw0XixX006ACXt/2G16Uu8i3wStz1J4DWvIUzL/UUEqw86Omo82FrnOt6l/YnZwQGF7KW3ZAX+6BhHItWw19UPVq6o2thT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609495; 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=KgYMNTVWGBUuNBvafXnBM/3JGglA6WgPf47qHGbvQkB6PGBFK8ScqyQu3pmA2oyY+5G8pXuNiO0wntjk8a8MwWA7ifx3zsM9hkNfCLxD2/NIUbWUtTQy9CWS4PSEoQwXQ1hoZJitruBGCDZ7PdaAHiBeDzHlE1XTWdUCWOQsih8= 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=1773609495; 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=A+FHKzaPzrOgjPIsz+y/T/qBtA74zcKllis6BmVDGC5pl8qKrZ9FScgo8lStt+GC 6EjJ8PKHE7FsFANWeStpPD1VaWHmTbcCPvnrjjA9p8W6xrVrc59fLwKPP8E8zgPbLGT ff8jUSakjLMfLzLyJMhDRQNXr83jDTMXQCRbyvAc= Received: by mx.zoho.eu with SMTPS id 1773609494489924.6100757135223; Sun, 15 Mar 2026 22:18:14 +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 v4 7/8] lib/tests: add kunit tests for glob_match_nocase() and glob_validate() Date: Sun, 15 Mar 2026 21:18:06 +0000 Message-Id: <20260315211807.411173-8-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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 Thu Apr 9 10:29:04 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 7253737C11D; Sun, 15 Mar 2026 21:18:27 +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=1773609512; cv=pass; b=KG0NCytmH75+NipcJzxpC9pWOfEIcGU7CLrW4BsVIkkKqAiWZUwT1a55Lr9oJiEO1f0/5Qpg7KZU2KsxkrzVQet/iJGLiLKHXBq9hIveuuc9xZ2DDjWOFPAAbVNynek7hq4kYigwzOIkUiU2sShQM2Pw0T0IZQEcpiPi674XcgE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773609512; c=relaxed/simple; bh=nDNdIz9w1v6GX9HKPOLSEpcSx9VPTmDZ0uZ7Lf2JPJQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=VhtR5k7fA1SnDG5pK0VP9fSn741HiO9Q7xO7SQUIlfW3f+74CzAKFqMbuIWDC8dgwKZCPerZ/DxvnAnDSlCeqPOIZqLnexz33XfvgLIxZOGsgjyhL7p4hMp+lPz6KOyVZVZskOJizH7S/qSOaPdLt+fM2IDq4wbJzy1TjWiUuHA= 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=l36v47qb; 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="l36v47qb" ARC-Seal: i=1; a=rsa-sha256; t=1773609498; cv=none; d=zohomail.eu; s=zohoarc; b=j2NQ4NaCPXhUZg34VA6Qc4tuEQhPUd+bVyGSoOyifS4zEKb1uACYYAgC1yEpmoe7nSQi7HgmPV0ToJa9CnpjWX8xF9QklCb+NDxUor9zgFJ7mOlDr2XAzzBeEyt3eQgHjOzGrXe2NlUqhM45fUix/5JdoMjWAWYs9BZX4NxisT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773609498; 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=Db2IYWbuiG7BCFVihBBMD9gYCz65QuvpZ3Byb4Po/YpjllmPiAVXGEFYNBcBk2sQHF7xbUDIyPImO8VbGHozx4G6QAsuxWUdYq+dLeEBNRXG2mgZJgj4FdO0J3QiVZub85lH97UHSoovUUrSGrpE8CH3IvXXmMDG/jYtlOwUGdA= 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=1773609498; 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=l36v47qbQKkOb7PfQaP9j7WCsgu74BQRK+YHQXkEiWo5xmX+Ys8HG6IJr8zIL7I7 8GUPbegq6MnnmzpMrjo3m2k1gJedQMEGtGX3DLGyn3n7p3X+Kx0LlqMv6RWygz2+C6p tuK5W7gU7VOIyFi9Tl6NPDXmbmU81ph6E4DHkX5o= Received: by mx.zoho.eu with SMTPS id 17736094951831004.9757762051256; Sun, 15 Mar 2026 22:18:15 +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 v4 8/8] kunit: validate glob filter patterns before use Date: Sun, 15 Mar 2026 21:18:07 +0000 Message-Id: <20260315211807.411173-9-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315211807.411173-1-objecting@objecting.org> References: <20260315211807.411173-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 Acked-by: David Gow Tested-by: David Gow Tested-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