From nobody Sun Nov 22 16:16:41 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jXZ2d3y1bz728Wd for ; Sun, 22 Nov 2026 16:16:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jXZ2d2XyRz560C for ; Sun, 22 Nov 2026 16:16:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795364201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/lus9vcKTU1NPG9aTwVQIch9Hhw69GZmeCYiKvo4juk=; b=FeuQN+mXesQEl5ddSeGZBCIt6L0nmS3XAvUl67fcXisLWQkuXozi0bhOWxHStcqRx1DL9g WvIl9sj9Fd+AhX/k7JWso5jAG/ebs2o4PxySB9goo8L+cHFa8WQHIRPB1CsK3GIo01GFIK jVo8FCuQY2VEuP9ggJB0Ty79cUK+ZhYEz+Hcss/bxTNjz6RymhjaVT5h3uCqh+QLXlD+Rv FBPdul3DATps0LSd9GAK9KEY/zKwIWOvP6ZOsjeTEkGjdh6XP0dZlbf3B8EnbkYc3wjwi0 pvCnAB84ogtsIzM4V/mnvIdWFL6kmdD9VnY+pYKAkGd1rprOtr+5/uKOSQH2QQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795364201; b=aR8B6NxK0km8p/Jvo4JahdgZks8I7/G6LkWOEmbhHQ6VMpey8qylaTLZu0nDY/xv9Qngv8 G289MbXTHhITNuyKwOpRyp//hZHPbUioq8T3g5UYpQE23uX32bT4iZd05W0dFS0zaz77VB 3WsuKpaifFF+P7bs7ImGmwbPCGKJJ+m39jo4TCftM+BQnVpnfKRu0+cOdkKi8FJGPkkXy9 qnpoAhMdFc3Rj8exd4X+1FVRdn/vrbdWoMqyrQeubJoXcy5HEdWKHflAIBci5vMhLffY3B HQx9ZVAbFAOoWjexRMO+C9ZZ/G7r9Z1pdgJYkajYubNAjWDHuAcevqxFzPfKrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795364201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/lus9vcKTU1NPG9aTwVQIch9Hhw69GZmeCYiKvo4juk=; b=OzUJVCOiTBKCyynbD2h9hFhuQQJtGIlARXUb78U3TAVklps2DL6S7TMjejUcFc0NpQGBoP UGUjK8udMbHDN2/n+JR9PnokhvE9WTu5TBhc/aSlLW65OQkVh+1VmSeIzeFItqQqVA/hix dZ944oKjd7oOvFgRBjp/nVEFWOP/aZ5ZSB7fJTFqStVY7QYjpR7NvVcX33LiP8AQTND8NR 8HkiXahPp1GzGLcILQlHjqx0E4kD0fFpDFzqwbUOr3WKUj5bsvgpERt2JHRptrLmRnTOGz SHgR0dAYfmbFOCSDcdy8N/Ln/t3J5mlQwyfnqIAVZXq0MeKyRmbo+Rgz7COq+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jXZ2d2C4nz1PlM for ; Sun, 22 Nov 2026 16:16:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 11ec6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 22 Nov 2026 16:16:41 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 11a3bc02374b - main - libc/fnmatch/rangematch: fix uninitialized variable read in a condition List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 11a3bc02374b6517e9bfcaaf68c9b5b9902c043c Auto-Submitted: auto-generated Date: Sun, 22 Nov 2026 16:16:41 +0000 Message-Id: <6b031569.11ec6.45148f95@gitrepo.freebsd.org> The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=11a3bc02374b6517e9bfcaaf68c9b5b9902c043c commit 11a3bc02374b6517e9bfcaaf68c9b5b9902c043c Author: Andriy Gapon AuthorDate: 2026-11-22 15:21:01 +0000 Commit: Andriy Gapon CommitDate: 2026-11-22 16:16:31 +0000 libc/fnmatch/rangematch: fix uninitialized variable read in a condition The condition was logically incorrect and could also result in access to an uninitialized variable. The bug happened because of misplaced parentheses in the complex condition. There is another very similar condition in the code and it has the correct placement, so it does not have the bug. I used it as an example for the fix. Both conditions came from the same commit af79566b9315. For me, the bug appeared as a random failure to match a simple pattern with '[0-9]' in it. The value of the uninitialized variable depended on the value left on the stack by other code, so the bug appeared only under very specific conditions. FWIW, gcc catches and reports the uninitialized variable problem. clang does it only with -Wconditional-uninitialized but that flag leads to too many false positives. I also found a pattern that deterministically reveals the bug in a different way without depending on the uninitialized value, through incorrect logic. The pattern is: '[[:alpha:]0-9]'. Easy demonstration: $ mkdir test && cd test $ touch a 5 $ find . -name '[[:alpha:]0-9]' ./a File '5' should also have been found. I've added a test case to cover that. Fixes: af79566b9315 MFC after: 1 week --- lib/libc/gen/fnmatch.c | 4 ++-- lib/libc/tests/gen/fnmatch_test.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c index 1bb020da229b..7605cf61315f 100644 --- a/lib/libc/gen/fnmatch.c +++ b/lib/libc/gen/fnmatch.c @@ -410,8 +410,8 @@ treat_like_collating_symbol: if (c2 == EOS) return (RANGE_ERROR); - if ((c2 == '[' && (special = *pattern) == '.') || - special == '=' || special == ':') { + if (c2 == '[' && ((special = *pattern) == '.' || + special == '=' || special == ':')) { /* * No equivalence classes or character diff --git a/lib/libc/tests/gen/fnmatch_test.c b/lib/libc/tests/gen/fnmatch_test.c index 0ff7400a4a4f..360a242cdad5 100644 --- a/lib/libc/tests/gen/fnmatch_test.c +++ b/lib/libc/tests/gen/fnmatch_test.c @@ -198,6 +198,9 @@ ATF_TC_BODY(fnmatch_characterclass, tc) ATF_CHECK(fnmatch("[[:punct:]]", ".", 0) == 0); ATF_CHECK(fnmatch("[[:xdigit:]]", "f", 0) == 0); + /* A range following a character class in the same bracket. */ + ATF_CHECK(fnmatch("[[:alpha:]0-9]", "5", 0) == 0); + /* * POSIX.1, section 9.3.5. states that '[:' and ':]' * should be interpreted as character classes symbol only