From patchwork Tue May 23 07:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Arenas X-Patchwork-Id: 1784882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=AACCKYfT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QQR4x0DkQz20Pb for ; Tue, 23 May 2023 17:38:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E6CF3856DD6 for ; Tue, 23 May 2023 07:38:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E6CF3856DD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684827503; bh=vidTEZu50Q26HWTibYVmNVOXmlts15wWkMnCpoD/k/o=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=AACCKYfTSBiSJZ/yo8kxMoySxdfyEaJVSET9LE7FTUmT1gvZwAz6a9OdAF4EAIZir R1RoLrzCJD20uQBKLxiMe7vcHrT1rVszEe12SU5M8Aa6UDFaAWNuiLC0+zlBSFejh2 WTLJSxbPHK3arY8ugvrI/UhOGeyTtxRl2revh2xI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 2D31A3858D38 for ; Tue, 23 May 2023 07:38:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D31A3858D38 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d247a023aso3818181b3a.2 for ; Tue, 23 May 2023 00:38:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684827485; x=1687419485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vidTEZu50Q26HWTibYVmNVOXmlts15wWkMnCpoD/k/o=; b=QpALujAAv54lMcDO+CCe/sCRinDWGXpojk9uXiML5LCQxaSdSb2rMFasGVZUyXyjML 32Ivm+E9rnEiYQ/3vjai3Kjsk3FXY5rS9xo9YB2bW30+SOpmRwXJmitpB6jxWfzpDbdI UufwUcIhvbjM0a5jjNme2rcpLaGICyhKIgWef/I4FOP1xD7LODvrhEaRJdqnFetyjChG v+Aw7RvfJ3N5PkaE72ORuxzHpN2otX/mWLJxgyhe4xu931A5yl9YvURBM44qLZ+MxPuj 0j7Znd/KSETu1Ju1Jbgdc+AlfDr1cYEDxVSwAzFushlVkGoPBhtRNn9qj2zOE4xHZ7D+ PLaw== X-Gm-Message-State: AC+VfDzpZlD8mbKv02CQdUC5Z9o/ac6xyYpVJw4YE1iavdP5b2wJIUBe ZwhyUV4gqOHlmk+kYSpfbnnNz6RaA7E= X-Google-Smtp-Source: ACHHUZ4a9k7IXqebRmJzO5WAnV7Ln2T6srzOWeg4tL+BdjS89i5+oQUFR3EfzhhiAZuX+Hqd23Nmww== X-Received: by 2002:a05:6a20:918e:b0:106:dfc8:6f5b with SMTP id v14-20020a056a20918e00b00106dfc86f5bmr14152741pzd.50.1684827484671; Tue, 23 May 2023 00:38:04 -0700 (PDT) Received: from localhost.localdomain (192-184-219-167.fiber.dynamic.sonic.net. [192.184.219.167]) by smtp.gmail.com with ESMTPSA id g6-20020a635206000000b0053051d50a48sm5410027pgb.79.2023.05.23.00.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 00:38:04 -0700 (PDT) To: libc-alpha@sourceware.org Cc: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= Subject: [PATCH 2/2] posix: correctly detect invalid classes after match in fnmatch() Date: Tue, 23 May 2023 00:37:32 -0700 Message-Id: <20230523073732.6956-3-carenas@gmail.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230523073732.6956-1-carenas@gmail.com> References: <20230523073732.6956-1-carenas@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n_via_Libc-alpha?= From: Carlo Arenas Reply-To: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Always validate class names when parsing a [:class:] expression * posix/fnmatch_loop.c (internal_fnmatch/internal_fnwmatch) remove comment about an specification bug that is no longer relevant adjust inequality to include 'z' as a valid character in class names replace soft failure with a hard one when invalid names are used --- posix/fnmatch_loop.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c index 4be2e20141..a6b5c69a95 100644 --- a/posix/fnmatch_loop.c +++ b/posix/fnmatch_loop.c @@ -866,29 +866,30 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, { if (*p == L_('\0')) return FNM_NOMATCH; - /* XXX 1003.2d11 is unclear if this is right. */ + ++p; } else if (c == L_('[') && *p == L_(':')) { - int c1 = 0; - const CHAR *startp = p; + CHAR str[CHAR_CLASS_MAX_LENGTH + 1]; + size_t c1 = 0; while (1) { c = *++p; - if (++c1 == CHAR_CLASS_MAX_LENGTH) - return FNM_NOMATCH; - - if (*p == L_(':') && p[1] == L_(']')) + if (c == L_(':') && p[1] == L_(']')) break; - if (c < L_('a') || c >= L_('z')) - { - p = startp - 2; - break; - } + if (c1 == CHAR_CLASS_MAX_LENGTH || + (c < L_('a') || c > L_('z'))) + return FNM_NOMATCH; + + str[c1++] = c; } + str[c1] = L_('\0'); + if (IS_CHAR_CLASS (str) == 0) + return FNM_NOMATCH; + p += 2; } else if (c == L_('[') && *p == L_('='))