From patchwork Thu Jun 15 17:12:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1795559 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=IHvWZ6jC; 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 4QhplT0wfYz20QH for ; Fri, 16 Jun 2023 03:13:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBA47385696B for ; Thu, 15 Jun 2023 17:13:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBA47385696B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686849186; bh=iQBQMucERQpSGVNSANSR2bQw3CkHi2A+qLWM0izLBCk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IHvWZ6jC5EQF0Q4YkZ5GGHf1YYRBhjFFpwu7JX1Ywfpfgw+WFE6f4HBnnjEsICSIv SmmMw/Rz3+0ru3bH2gDGAzCmpDMqkgwkmNKH4BZbrWTK5kwhTXaYUmhg4hZ+IJUdGq sLk3khB+e58dMH7XqUiILTzXs04/uiTNg7efVmxc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 859C73857737 for ; Thu, 15 Jun 2023 17:12:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 859C73857737 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-ik9WAPDNOJWesmyTVvFCJQ-1; Thu, 15 Jun 2023 13:12:47 -0400 X-MC-Unique: ik9WAPDNOJWesmyTVvFCJQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-621257e86daso43704656d6.1 for ; Thu, 15 Jun 2023 10:12:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686849167; x=1689441167; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iQBQMucERQpSGVNSANSR2bQw3CkHi2A+qLWM0izLBCk=; b=PKH7wjNt80yvrJ85d+sal3w0YQORfdxGUHRUu9JhOUpH6x0h9dkH31qNIXOTlUrS4L QW7PSBI8kNsQCl2BwDMtKhnzNdPLz6e/f3IJE6m3OQz7oaI6Oflfydt8YXfPx9ezRjqz WK67A2QP2OY3AQUUIY5mC8XGNW2e6F4rbZqHDl9EfiNmxxXuObrimtBt+yxKgXFrEpbx 4P0bNrsXJltJNldL6mNdlaUB4sKQbubrj6DmlmzOMJ39D+FTg1woiY7BC1H94bEMEAYl AnA62Kra9wHgFFcDVngLA0JwbXMj6it2eg5jFPWt3fgOftq+hZk8TqFw4cuX9+lzFjar B8ag== X-Gm-Message-State: AC+VfDztJIuaeEOs5p4XHGO80pMGWCSunmv/H/So94tSrhlQzeoepDXC F0eVsbot4FzfKDtdTkSAXytodm4X6q1qs4WnfrkiWUO1u7JU1biciu36WSDnui5Q3o2QVhoVe8V G20mLIcx2jHAJ05crGeu0s7FTsI1QRRYUIcE6wLCJIRsg0nMcDmLTJMiW7vRCul7+JuWj2mleVl lt05wi X-Received: by 2002:a05:6214:489:b0:62d:feee:252e with SMTP id pt9-20020a056214048900b0062dfeee252emr9471375qvb.55.1686849166815; Thu, 15 Jun 2023 10:12:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gvKU8Ld3yKgoft4gAGtngHstV66lRRzn40GtYd/KwNMS2EK2YhT1Y9O9JFXkOxNGtuP0U+w== X-Received: by 2002:a05:6214:489:b0:62d:feee:252e with SMTP id pt9-20020a056214048900b0062dfeee252emr9471350qvb.55.1686849166499; Thu, 15 Jun 2023 10:12:46 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id k12-20020a0cb24c000000b0061c7431810esm5937431qve.141.2023.06.15.10.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 10:12:45 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2] fileops: Don't process , ccs= as individual mode flags (BZ#18906) Date: Thu, 15 Jun 2023 13:12:43 -0400 Message-Id: <20230615171243.4173020-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" In processing the first 7 individual characters of the mode for fopen if ,ccs= is used those characters will be processed as well. Stop processing individual mode flags once a comma is encountered. This has the effect of requiring ,ccs= to be the last mode flag in the mode string. Add a testcase to check that the ,ccs= mode flag is not processed as individual mode flags. --- Changes to v1: * fclose fp when fopen succeeds. Fixes memory leak found by try-bot libio/fileops.c | 1 + libio/tst-fopenloc.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libio/fileops.c b/libio/fileops.c index 58c9e985e4..1c1113e339 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -247,6 +247,7 @@ _IO_new_file_fopen (FILE *fp, const char *filename, const char *mode, switch (*++mode) { case '\0': + case ',': break; case '+': omode = O_RDWR; diff --git a/libio/tst-fopenloc.c b/libio/tst-fopenloc.c index 089c61bf41..8cd35f01f2 100644 --- a/libio/tst-fopenloc.c +++ b/libio/tst-fopenloc.c @@ -17,6 +17,7 @@ . */ #include +#include #include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include #include #include @@ -48,13 +50,40 @@ do_bz17916 (void) if (fp != NULL) { printf ("unexpected success\n"); + free (ccs); + fclose (fp); return 1; } + free (ccs); return 0; } +static int +do_bz18906 (void) +{ + /* BZ #18906 -- check processing of ,ccs= as flags case. */ + + const char *ccs = "r,ccs=+ISO-8859-1"; + size_t retval; + + FILE *fp = fopen (inputfile, ccs); + int flags; + + TEST_VERIFY(fp != NULL); + + if (fp != NULL) + { + flags = fcntl(fileno(fp), F_GETFL); + retval = (flags & O_RDWR) | (flags & O_WRONLY); + TEST_COMPARE(retval, false); + fclose (fp); + } + + return EXIT_SUCCESS; +} + static int do_test (void) { @@ -78,7 +107,10 @@ do_test (void) xfclose (fp); - return do_bz17916 (); + TEST_COMPARE(do_bz17916 (), 0); + TEST_COMPARE(do_bz18906 (), 0); + + return EXIT_SUCCESS; } #include