* [PATCH v2] fileops: Don't process ,ccs= as individual mode flags (BZ#18906)
@ 2023-06-15 17:12 Joe Simmons-Talbott
2023-07-05 18:18 ` Joe Simmons-Talbott
2023-07-05 19:45 ` [PATCH v2] fileops: Don't process , ccs= " DJ Delorie
0 siblings, 2 replies; 4+ messages in thread
From: Joe Simmons-Talbott @ 2023-06-15 17:12 UTC (permalink / raw)
To: libc-alpha; +Cc: Joe Simmons-Talbott
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 @@
<https://www.gnu.org/licenses/>. */
#include <errno.h>
+#include <fcntl.h>
#include <locale.h>
#include <mcheck.h>
#include <stdio.h>
@@ -24,6 +25,7 @@
#include <string.h>
#include <wchar.h>
#include <sys/resource.h>
+#include <support/check.h>
#include <support/support.h>
#include <support/xstdio.h>
@@ -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 <support/test-driver.c>
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fileops: Don't process ,ccs= as individual mode flags (BZ#18906)
2023-06-15 17:12 [PATCH v2] fileops: Don't process ,ccs= as individual mode flags (BZ#18906) Joe Simmons-Talbott
@ 2023-07-05 18:18 ` Joe Simmons-Talbott
2023-07-05 19:45 ` [PATCH v2] fileops: Don't process , ccs= " DJ Delorie
1 sibling, 0 replies; 4+ messages in thread
From: Joe Simmons-Talbott @ 2023-07-05 18:18 UTC (permalink / raw)
To: libc-alpha
On Thu, Jun 15, 2023 at 01:12:43PM -0400, Joe Simmons-Talbott wrote:
> 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
Ping.
Thanks,
Joe
>
> 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 @@
> <https://www.gnu.org/licenses/>. */
>
> #include <errno.h>
> +#include <fcntl.h>
> #include <locale.h>
> #include <mcheck.h>
> #include <stdio.h>
> @@ -24,6 +25,7 @@
> #include <string.h>
> #include <wchar.h>
> #include <sys/resource.h>
> +#include <support/check.h>
> #include <support/support.h>
> #include <support/xstdio.h>
>
> @@ -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 <support/test-driver.c>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fileops: Don't process , ccs= as individual mode flags (BZ#18906)
2023-06-15 17:12 [PATCH v2] fileops: Don't process ,ccs= as individual mode flags (BZ#18906) Joe Simmons-Talbott
2023-07-05 18:18 ` Joe Simmons-Talbott
@ 2023-07-05 19:45 ` DJ Delorie
2023-07-05 20:31 ` Joe Simmons-Talbott
1 sibling, 1 reply; 4+ messages in thread
From: DJ Delorie @ 2023-07-05 19:45 UTC (permalink / raw)
To: Joe Simmons-Talbott; +Cc: libc-alpha
This patch looks semantically correct to me, but needs a few syntactical
changes to meet our coding style. Please post a v3 and I'll prioritize
re-reviewing it. Thanks!
Joe Simmons-Talbott via Libc-alpha <libc-alpha@sourceware.org> writes:
> 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;
While this does force the ,ccs= to be after any other flags, effectively
this was true before as the characters in "ccs" and/or the conversion
name would conflict anyway. Ok.
> 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 @@
> <https://www.gnu.org/licenses/>. */
>
> #include <errno.h>
> +#include <fcntl.h>
> #include <locale.h>
> #include <mcheck.h>
> #include <stdio.h>
> @@ -24,6 +25,7 @@
> #include <string.h>
> #include <wchar.h>
> #include <sys/resource.h>
> +#include <support/check.h>
> #include <support/support.h>
> #include <support/xstdio.h>
>
> @@ -48,13 +50,40 @@ do_bz17916 (void)
> if (fp != NULL)
> {
> printf ("unexpected success\n");
> + free (ccs);
> + fclose (fp);
> return 1;
> }
> +
> free (ccs);
>
> return 0;
> }
Ok.
> +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;
> +}
Ok. Needs space between "TEST_VERIFY" and "(" though, and
"TEST_COMPARE" and "("
Needs spaces in fcntl( and fileno(
> @@ -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;
> }
Ok, but same here - needs spaces before parens.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fileops: Don't process , ccs= as individual mode flags (BZ#18906)
2023-07-05 19:45 ` [PATCH v2] fileops: Don't process , ccs= " DJ Delorie
@ 2023-07-05 20:31 ` Joe Simmons-Talbott
0 siblings, 0 replies; 4+ messages in thread
From: Joe Simmons-Talbott @ 2023-07-05 20:31 UTC (permalink / raw)
To: DJ Delorie; +Cc: libc-alpha
On Wed, Jul 05, 2023 at 03:45:03PM -0400, DJ Delorie wrote:
>
> This patch looks semantically correct to me, but needs a few syntactical
> changes to meet our coding style. Please post a v3 and I'll prioritize
> re-reviewing it. Thanks!
Thanks for reviewing it. I've posted a v3 with the changes you've
suggested.
Thanks,
Joe
>
> Joe Simmons-Talbott via Libc-alpha <libc-alpha@sourceware.org> writes:
> > 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;
>
> While this does force the ,ccs= to be after any other flags, effectively
> this was true before as the characters in "ccs" and/or the conversion
> name would conflict anyway. Ok.
>
> > 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 @@
> > <https://www.gnu.org/licenses/>. */
> >
> > #include <errno.h>
> > +#include <fcntl.h>
> > #include <locale.h>
> > #include <mcheck.h>
> > #include <stdio.h>
> > @@ -24,6 +25,7 @@
> > #include <string.h>
> > #include <wchar.h>
> > #include <sys/resource.h>
> > +#include <support/check.h>
> > #include <support/support.h>
> > #include <support/xstdio.h>
> >
> > @@ -48,13 +50,40 @@ do_bz17916 (void)
> > if (fp != NULL)
> > {
> > printf ("unexpected success\n");
> > + free (ccs);
> > + fclose (fp);
> > return 1;
> > }
> > +
> > free (ccs);
> >
> > return 0;
> > }
>
> Ok.
>
> > +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;
> > +}
>
> Ok. Needs space between "TEST_VERIFY" and "(" though, and
> "TEST_COMPARE" and "("
>
> Needs spaces in fcntl( and fileno(
>
> > @@ -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;
> > }
>
> Ok, but same here - needs spaces before parens.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-05 20:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 17:12 [PATCH v2] fileops: Don't process ,ccs= as individual mode flags (BZ#18906) Joe Simmons-Talbott
2023-07-05 18:18 ` Joe Simmons-Talbott
2023-07-05 19:45 ` [PATCH v2] fileops: Don't process , ccs= " DJ Delorie
2023-07-05 20:31 ` Joe Simmons-Talbott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).