From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7932) id 34B993856DF1; Wed, 5 Jul 2023 21:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34B993856DF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688593766; bh=Q1uhYw3Jh3x5UtorZKbiVaihZhPLk3owHelmqhpxoEA=; h=From:To:Subject:Date:From; b=XkppotE4PTQFZd5d5VFgvyPXV5p/ShoBzT6u65IfQOn9iSE8GJQOo2sVbYXFjXIJ2 kXGp8CATTnmiNEr+z/QVPVgkdzvgpgCm+7EkF6CjrxzhgC6MZPynT/Gi8FxOWV1GVZ InFzmgY87u0qeIsFfXonnZxRev+358qOp0fxWkcU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Joe Simmons-Talbott To: glibc-cvs@sourceware.org Subject: [glibc] fileops: Don't process , ccs= as individual mode flags (BZ#18906) X-Act-Checkin: glibc X-Git-Author: Joe Simmons-Talbott X-Git-Refname: refs/heads/master X-Git-Oldrev: 02261d1bd930b50e9166086462dca885e9847826 X-Git-Newrev: 5324d258427fd11ca0f4f595c94016e568b26d6b Message-Id: <20230705214926.34B993856DF1@sourceware.org> Date: Wed, 5 Jul 2023 21:49:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5324d258427fd11ca0f4f595c94016e568b26d6b commit 5324d258427fd11ca0f4f595c94016e568b26d6b Author: Joe Simmons-Talbott Date: Wed Jul 5 21:23:28 2023 +0000 fileops: Don't process ,ccs= as individual mode flags (BZ#18906) 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. Reviewed-by: DJ Delorie Diff: --- 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