From patchwork Wed Jul 5 20:29:11 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: 1804014 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=server2.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=SBK4LD4L; dkim-atps=neutral Received: from server2.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 4QxB8z14CCz20ZQ for ; Thu, 6 Jul 2023 06:29:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6F013857011 for ; Wed, 5 Jul 2023 20:29:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6F013857011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688588975; bh=vUVv0Cy4k0tXvrBBuTnetZJe7bHRFRA0JsNHL1pFshw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SBK4LD4LLVr2kO1zBWDE8YhcZXKaLnQpQnBbjjY4yCEaSXT5mxs06XzCxDO2clEvc GUgRo4o1wNvy64ObHsm696qwzYKkpvrhEMrxgl6R5wO1rjNGTx1tmqot61FlM9yiiV SPCRQhY3J2/vQovxrzGeIPUU5wkPDJEgLIsRCkzQ= 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 169DE3858C62 for ; Wed, 5 Jul 2023 20:29:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 169DE3858C62 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-1-5QhaBvzeOgWdzsR8RNBEuA-1; Wed, 05 Jul 2023 16:29:19 -0400 X-MC-Unique: 5QhaBvzeOgWdzsR8RNBEuA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-635ed44d2afso715976d6.2 for ; Wed, 05 Jul 2023 13:29:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688588958; x=1691180958; 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=vUVv0Cy4k0tXvrBBuTnetZJe7bHRFRA0JsNHL1pFshw=; b=MZlleZkalS+9O20v8HDt+ZBl/tg6RnhOSO3yQw+3PHYnV1A9aiqCXCBmeY29y6fQM7 3hmGI6G3N49mYH+hFkytyNTQ/MZr2Y3hurJUybLGOAm5yMbTntYn32QtUtswvd/PUJaH CbqPnyRm5oeovBbeUqNX76fCjOThNUjki/fTKij4xgUGQEjXymDpkCXLkd7sF5o2FfC5 i3LLbu9+9DiWIbUoG4ioY4psdhRrrVfLwud9E0qvZoEmbJMYRInzkwEJLtFakwZglIWw TzEwbHcfrnap2qvnISHbPIef56hkVCdOPr2MF9uAzJSISwudmG1Ry0xcHJhBhgRJoZzH EdRA== X-Gm-Message-State: ABy/qLZV/hqS9JVkB7NHc8KiKRawfMPSil9UdO5A5gEHgbgtsn5vriEy OE2IPiAAmYQVBIjVtRNi9aWYwfpzHYmJSD7tINbzx8SycRCCP7I6JndxLkCqmCRSOx9he+G+Q5Y xJOUBuuKiJ/nyCNS23DpTQtL/1/oXj5TEBPCN21WiUqxDUU2bgLfiCkYh5STaUy1xmLdSi8jO79 KhKGvL X-Received: by 2002:a05:6214:e6b:b0:62d:ddeb:3782 with SMTP id jz11-20020a0562140e6b00b0062dddeb3782mr15488790qvb.49.1688588958593; Wed, 05 Jul 2023 13:29:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQOBNsrMn1BrUSgJt2c7gq3xujMDeWYZWpa7ktwzmvOvq745n2DgYM5vtZ3CLdjjPdXMDBGA== X-Received: by 2002:a05:6214:e6b:b0:62d:ddeb:3782 with SMTP id jz11-20020a0562140e6b00b0062dddeb3782mr15488773qvb.49.1688588958214; Wed, 05 Jul 2023 13:29:18 -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 t5-20020a05621405c500b00636291d04adsm7726319qvz.47.2023.07.05.13.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 13:29:17 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v3] fileops: Don't process , ccs= as individual mode flags (BZ#18906) Date: Wed, 5 Jul 2023 16:29:11 -0400 Message-Id: <20230705202911.1480449-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.5 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 v2: * Fix style issues: space before parens. 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..5b3c1849ef 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