* [PATCH] kconfig: fix missing fclose() on error paths
@ 2022-02-08 6:26 Masahiro Yamada
2022-02-10 0:53 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2022-02-08 6:26 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, Ryan Cai, linux-kernel
The file is not closed when ferror() fails.
Fixes: 00d674cb3536 ("kconfig: refactor conf_write_dep()")
Fixes: 57ddd07c4560 ("kconfig: refactor conf_write_autoconf()")
Reported-by: Ryan Cai <ycaibb@gmail.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/confdata.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 59717be31210..16897cb8cefd 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -979,10 +979,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
fprintf(out, "\n$(deps_config): ;\n");
- if (ferror(out)) /* error check for all fprintf() calls */
- return -1;
-
+ ret = ferror(out); /* error check for all fprintf() calls */
fclose(out);
+ if (ret)
+ return -1;
if (rename(tmp, name)) {
perror("rename");
@@ -1093,10 +1093,10 @@ static int __conf_write_autoconf(const char *filename,
print_symbol(file, sym);
/* check possible errors in conf_write_heading() and print_symbol() */
- if (ferror(file))
- return -1;
-
+ ret = ferror(file);
fclose(file);
+ if (ret)
+ return -1;
if (rename(tmp, filename)) {
perror("rename");
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: fix missing fclose() on error paths
2022-02-08 6:26 [PATCH] kconfig: fix missing fclose() on error paths Masahiro Yamada
@ 2022-02-10 0:53 ` Masahiro Yamada
2022-02-11 11:46 ` David Laight
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2022-02-10 0:53 UTC (permalink / raw)
To: Linux Kbuild mailing list; +Cc: Ryan Cai, Linux Kernel Mailing List
On Tue, Feb 8, 2022 at 3:26 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> The file is not closed when ferror() fails.
>
> Fixes: 00d674cb3536 ("kconfig: refactor conf_write_dep()")
> Fixes: 57ddd07c4560 ("kconfig: refactor conf_write_autoconf()")
> Reported-by: Ryan Cai <ycaibb@gmail.com>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
Applied to linux-kbuild/fixes.
>
> scripts/kconfig/confdata.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 59717be31210..16897cb8cefd 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -979,10 +979,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
>
> fprintf(out, "\n$(deps_config): ;\n");
>
> - if (ferror(out)) /* error check for all fprintf() calls */
> - return -1;
> -
> + ret = ferror(out); /* error check for all fprintf() calls */
> fclose(out);
> + if (ret)
> + return -1;
>
> if (rename(tmp, name)) {
> perror("rename");
> @@ -1093,10 +1093,10 @@ static int __conf_write_autoconf(const char *filename,
> print_symbol(file, sym);
>
> /* check possible errors in conf_write_heading() and print_symbol() */
> - if (ferror(file))
> - return -1;
> -
> + ret = ferror(file);
> fclose(file);
> + if (ret)
> + return -1;
>
> if (rename(tmp, filename)) {
> perror("rename");
> --
> 2.32.0
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] kconfig: fix missing fclose() on error paths
2022-02-10 0:53 ` Masahiro Yamada
@ 2022-02-11 11:46 ` David Laight
2022-02-12 16:09 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: David Laight @ 2022-02-11 11:46 UTC (permalink / raw)
To: 'Masahiro Yamada', Linux Kbuild mailing list
Cc: Ryan Cai, Linux Kernel Mailing List
From: Masahiro Yamada
> Sent: 10 February 2022 00:54
> >
> > The file is not closed when ferror() fails.
> >
> > Fixes: 00d674cb3536 ("kconfig: refactor conf_write_dep()")
> > Fixes: 57ddd07c4560 ("kconfig: refactor conf_write_autoconf()")
> > Reported-by: Ryan Cai <ycaibb@gmail.com>
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
>
>
> Applied to linux-kbuild/fixes.
>
>
> >
> > scripts/kconfig/confdata.c | 12 ++++++------
> > 1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> > index 59717be31210..16897cb8cefd 100644
> > --- a/scripts/kconfig/confdata.c
> > +++ b/scripts/kconfig/confdata.c
> > @@ -979,10 +979,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
> >
> > fprintf(out, "\n$(deps_config): ;\n");
> >
> > - if (ferror(out)) /* error check for all fprintf() calls */
> > - return -1;
> > -
> > + ret = ferror(out); /* error check for all fprintf() calls */
> > fclose(out);
> > + if (ret)
> > + return -1;
There's not much point calling ferror() unless you call fflush() first.
Similarly there's about zero point in checking the return from fprintf().
At least I've never found any distro adding 'must_check' to fprintf().
('must_not_check' would be more appropriate!)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: fix missing fclose() on error paths
2022-02-11 11:46 ` David Laight
@ 2022-02-12 16:09 ` Masahiro Yamada
0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-02-12 16:09 UTC (permalink / raw)
To: David Laight
Cc: Linux Kbuild mailing list, Ryan Cai, Linux Kernel Mailing List
On Fri, Feb 11, 2022 at 8:47 PM David Laight <David.Laight@aculab.com> wrote:
>
> From: Masahiro Yamada
> > Sent: 10 February 2022 00:54
> > >
> > > The file is not closed when ferror() fails.
> > >
> > > Fixes: 00d674cb3536 ("kconfig: refactor conf_write_dep()")
> > > Fixes: 57ddd07c4560 ("kconfig: refactor conf_write_autoconf()")
> > > Reported-by: Ryan Cai <ycaibb@gmail.com>
> > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > ---
> >
> >
> > Applied to linux-kbuild/fixes.
> >
> >
> > >
> > > scripts/kconfig/confdata.c | 12 ++++++------
> > > 1 file changed, 6 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> > > index 59717be31210..16897cb8cefd 100644
> > > --- a/scripts/kconfig/confdata.c
> > > +++ b/scripts/kconfig/confdata.c
> > > @@ -979,10 +979,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
> > >
> > > fprintf(out, "\n$(deps_config): ;\n");
> > >
> > > - if (ferror(out)) /* error check for all fprintf() calls */
> > > - return -1;
> > > -
> > > + ret = ferror(out); /* error check for all fprintf() calls */
> > > fclose(out);
> > > + if (ret)
> > > + return -1;
>
> There's not much point calling ferror() unless you call fflush() first.
>
> Similarly there's about zero point in checking the return from fprintf().
> At least I've never found any distro adding 'must_check' to fprintf().
> ('must_not_check' would be more appropriate!)
Thanks for pointing it out. You are right.
I assume you are not opposed to this patch itself.
I will insert fflush() before ferror()
as a separate patch.
> David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-12 16:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 6:26 [PATCH] kconfig: fix missing fclose() on error paths Masahiro Yamada
2022-02-10 0:53 ` Masahiro Yamada
2022-02-11 11:46 ` David Laight
2022-02-12 16:09 ` Masahiro Yamada
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 NNTP newsgroup(s).