Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: sergos <sergos@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix io.close().
Date: Thu, 14 Jul 2022 11:04:00 +0300	[thread overview]
Message-ID: <Ys/N8NSmC14xzdU0@root> (raw)
In-Reply-To: <F0DF6463-19EA-4666-B7E1-4DAC179E49C8@tarantool.org>

Hi, Sergos!

Thanks for the review!

On 13.07.22, sergos wrote:
> Hi!
> 
> Thanks for the patch!
> 
> Just some minor nits.

Updated the commit message to the following:

===================================================================
Fix io.close().

Reported by farmboy0.

When an `io.close()` is called without arguments on an already closed
default output, the underlying `iof->fp` is already NULL. So, the
following call to the `fclose()` leads to a SEGFAULT.

This patch adds the corresponding check by using of the `io_stdfile()`
instead of the `IOSTDF_IOF()`.

Also, this patch refactors several internal functions by changing the
argument type from the `FILE *` to the `IOFileUD *`.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#7230
===================================================================

> 
> LGTM
> Sergos
> 
> > On 18 May 2022, at 11:58, Sergey Kaplun <skaplun@tarantool.org> wrote:
> > 
> > From: Mike Pall <mike>
> > 
> > Reported by farmboy0.
> > 
> > When `io.close()` is called without arguments on already closed default
>       ^                                           ^
>      an                                          an
> > output `iof->fp` is already NULL. So, the forward call to `fclose()`
>         ^                                   ^              ^
>        the underlying                       following(?)   the
> > leads to SEGFAULT.
>           ^
>           a
> > 
> > This patch adds the corresponding check by using `io_stdfile()` instead
>                                                   ^
>                                                   of the
> > `IOSTDF_IOF()`.
>  ^
>  of the
> > 
> > Also, this patch refactors several internal functions by changing
> > the argument type from `FILE *` to `IOFileUD *`.
>                         ^           ^
>                         the         the
> > 
> > Sergey Kaplun:
> > * added the description and the test for the problem
> > ---
> > src/lib_io.c                                  | 20 +++++++++--------
> > .../lj-735-io-close-on-closed-file.test.lua   | 22 +++++++++++++++++++
> > 2 files changed, 33 insertions(+), 9 deletions(-)
> > create mode 100644 test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
> > 
> > diff --git a/src/lib_io.c b/src/lib_io.c
> > index 9763ed46..d9028938 100644
> > --- a/src/lib_io.c
> > +++ b/src/lib_io.c

<snipped>

> > diff --git a/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
> > new file mode 100644
> > index 00000000..795dad6c
> > --- /dev/null
> > +++ b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
> > @@ -0,0 +1,22 @@
> > +local tap = require('tap')
> > +
> > +local test = tap.test('lj-735-io-close-on-closed-file')
> > +test:plan(1)
> > +
> > +local TEST_FILE = 'lj-735-io-close-on-closed-file.tmp'
> > +
> > +local oldstdout = io.output()
> > +io.output(TEST_FILE)
> > +
> > +local status, err = io.close()
> > +assert(status, err)
> > +
> > +status = pcall(io.close)
> > +
> > +io.output(oldstdout)
> 
> Was not clear that you keep an old one for the test output, comment?

Yep, add the corresponding comment:

===================================================================
diff --git a/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
index 795dad6c..758c67a8 100644
--- a/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
+++ b/test/tarantool-tests/lj-735-io-close-on-closed-file.test.lua
@@ -5,6 +5,7 @@ test:plan(1)
 
 local TEST_FILE = 'lj-735-io-close-on-closed-file.tmp'
 
+-- Save the old stdout for the TAP output.
 local oldstdout = io.output()
 io.output(TEST_FILE)
 
===================================================================

> 
> > +
> > +test:ok(not status, 'close already closed file')
> > +
> > +assert(os.remove(TEST_FILE))
> > +
> > +os.exit(test:check() and 0 or 1)
> > -- 
> > 2.34.1
> > 
> 

-- 
Best regards,
Sergey Kaplun

  reply	other threads:[~2022-07-14  8:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18  8:58 [Tarantool-patches] [PATCH luajit 0/2] " Sergey Kaplun via Tarantool-patches
2022-05-18  8:58 ` [Tarantool-patches] [PATCH luajit 1/2] " Sergey Kaplun via Tarantool-patches
2022-07-13 11:58   ` sergos via Tarantool-patches
2022-07-14  8:04     ` Sergey Kaplun via Tarantool-patches [this message]
2022-05-18  8:58 ` [Tarantool-patches] [PATCH luajit 2/2] Fix io.close() error message Sergey Kaplun via Tarantool-patches
2022-07-13 11:58   ` sergos via Tarantool-patches
2022-07-14  7:54     ` Sergey Kaplun via Tarantool-patches
2022-07-13 11:58 ` [Tarantool-patches] [PATCH luajit 0/2] Fix io.close() sergos via Tarantool-patches
2022-07-13 17:45   ` Sergey Kaplun via Tarantool-patches
2022-11-23  7:50 ` Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ys/N8NSmC14xzdU0@root \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergos@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 1/2] Fix io.close().' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox