From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 66EF56ECE3; Thu, 14 Jul 2022 11:06:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 66EF56ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1657785983; bh=uUn3CWswdhNJWzsydiPpmIQ6uCJ5YwOgj9YFqpxvWNs=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=q4NuUkXHYVe+QTzuo7xbmXIFGRXIPxIeNZ691n2BKJsZkarsydS3uUDDU+9OVB4Ru t01YyWAr4PIsgn9ZJilB+TDEf01QpTAY2mpli+VKxdqQyUknukkez56WXiGhZfLon0 Yu/c6bKeHCLyUdxTvwIBjAMbz+DNa24u02M+23dM= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [94.100.177.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E91AA6ECE3 for ; Thu, 14 Jul 2022 11:06:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E91AA6ECE3 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1oBtrZ-0007FY-6A; Thu, 14 Jul 2022 11:06:21 +0300 Date: Thu, 14 Jul 2022 11:04:00 +0300 To: sergos Message-ID: References: <52271fcc9139dbf02d98b384a50cc13d1a02abb6.1652863494.git.skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9E1E7861EDEC0DEA65A68347C9B259EB908949543F36DD78A00894C459B0CD1B9C43FB154FC218E9B3839D6F28BBE66E2EB78FBC389580AC7813722A3219C69FF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F65C230EDDCD559EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372D22CC9620B7D5068638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C5F973EACDABF316EFD4070C87A6FD55117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAB5495298CADBD05A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB89ED3C7A6281781302FCEF25BFAB3454AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3ADEF88395FA75C5F76E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CB24F08513AFFAC7943847C11F186F3C59DAA53EE0834AAEE X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0F56C66D0505D9834EEDD2DF4914E7A12A28C5E499B74A421258957CDA9CDD5399C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349A401E2B4D763A4A57B106F357D90DE8E3D5BF4B1D22EDBE7C4E829811152530F508E1BCC35752061D7E09C32AA3244C7AD0430B2AAC076ECD21E18787F176E7A90944CA99CF22E3FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojpV6+aF9js3/jmPNWDrU2Lg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769C8D60ADB74DA3944CC7EF9A3C7DD73237962F9E9328436E1DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix io.close(). X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 wrote: > > > > From: Mike Pall > > > > 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 > > 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