From patchwork Tue May 23 07:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Arenas X-Patchwork-Id: 1784879 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=8.43.85.97; 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=Gz5q0TdM; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4QQR4t2jG5z20Q6 for ; Tue, 23 May 2023 17:38:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D20643857738 for ; Tue, 23 May 2023 07:38:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D20643857738 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684827499; bh=t1GqtSNRNaiymfoDT5uEWDCAppBHQn0WM4qRxlckt44=; 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=Gz5q0TdM6IxJMAjdIrs4gps5N9DtCNT2HTtMmD4xWinTvjXtR2h9s9O/0MD7wOmKC YfwLad5skGas8Lu34XOLu9VvZkfkykycCPhiUqfEZcjzNSzO+wYMKDe26tBzFw9VPA ed9YM02XbfpjWPcHkhibbmULvHOtVIdfjChPbXGw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 112863858D35 for ; Tue, 23 May 2023 07:38:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 112863858D35 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2554696544cso1967726a91.2 for ; Tue, 23 May 2023 00:38:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684827484; x=1687419484; 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=t1GqtSNRNaiymfoDT5uEWDCAppBHQn0WM4qRxlckt44=; b=SaIthOb9vDd9LSTLlU20KS2SfmXtZyMPwS4mp1TbGLH4XpfzEODTFS+HKjLlf6V/7x /sP4DWUe1sx2S6LWzP7R6Sruw+GY6PTb7H2pHKpPKOXejQRWMI5VTTbfkPG5eJMrP0oj 8yKiJgEXt/DZbJFMMtiCq+DFQ+ft2sZmeJD44E4arOmAEV6VzjisI36dIs9rRqTXj/3w dQ5ZGn8q94E7JhL6ZaERwiSMBfMs/IhTBIeWb36h92iiimbdh6tqfLy78E6iLWBpHA/w 5C6CDh/5dLtPbL7FnwSXTHhplJdvILGvzXQunRWGYKDwtboUpy/jm1RUwI9anDtSQgEd yMEg== X-Gm-Message-State: AC+VfDwPMIexKpPTRp75MpzN67NUiFHJSmFgrVtCzGUb7iG12+6BnBMD +Q5kzQnTYd8VB35NJoh5scw5EjaFo2s= X-Google-Smtp-Source: ACHHUZ4m5CweKVegka25r0HyeFYXf7TkjX7gQZx1s9brMxeGk9tHp/BrKopeYwYpmGwFDhkBZkoudg== X-Received: by 2002:a17:90a:2e12:b0:253:3ce4:b421 with SMTP id q18-20020a17090a2e1200b002533ce4b421mr12030650pjd.1.1684827483560; Tue, 23 May 2023 00:38:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 00:38:02 -0700 (PDT) To: libc-alpha@sourceware.org Cc: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= Subject: [PATCH 1/2] fnmatch: allow character class names with 'z' Date: Tue, 23 May 2023 00:37:31 -0700 Message-Id: <20230523073732.6956-2-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=-9.2 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" Since d8aaef00a7 (Update., 1999-04-26), there is code to consider character class names that include that character as invalid * posix/fnmatch_loop.c: correct inequality Copyright-paperwork-exempt: yes --- posix/fnmatch_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c index 8aeec9816f..4be2e20141 100644 --- a/posix/fnmatch_loop.c +++ b/posix/fnmatch_loop.c @@ -283,7 +283,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, p += 2; break; } - if (c < L_('a') || c >= L_('z')) + if (c < L_('a') || c > L_('z')) { /* This cannot possibly be a character class name. Match it as a normal range. */ 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_('='))