GNU bug report logs - #9762
tac fails when given multiple non-seekable inputs due to misuse of mkstemp()

Previous Next

Package: coreutils;

Reported by: Ambrose Feinstein <ambrose <at> google.com>

Date: Sat, 15 Oct 2011 20:58:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Ambrose Feinstein <ambrose <at> google.com>
Subject: bug#9762: closed (Re: bug#9762: tac fails when given multiple
 non-seekable inputs due to misuse of mkstemp())
Date: Wed, 19 Oct 2011 07:36:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#9762: tac fails when given multiple non-seekable inputs due to misuse of mkstemp()

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 9762 <at> debbugs.gnu.org.

-- 
9762: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9762
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Jim Meyering <jim <at> meyering.net>
To: Ambrose Feinstein <ambrose <at> google.com>
Cc: 9762-done <at> debbugs.gnu.org
Subject: Re: bug#9762: tac fails when given multiple non-seekable inputs due
	to misuse of mkstemp()
Date: Wed, 19 Oct 2011 09:34:39 +0200
Jim Meyering wrote:
> Ambrose Feinstein wrote:
>> Thanks for the quick fix!
>>
>> Aside from it requiring rearranging other code to not close the fd,
>> was there a reason not to reuse a single temp file?
>
> Actually that's what I started doing, but the change seemed like it'd
> end up being bigger than I wanted for a bug fix.  In retrospect, now
> that I've done it and see the extent, it would have been ok.
>
> Especially once I considered another factor: we want to avoid use of
> functions like xmalloc and file_name_concat that call exit upon failure.
> See the log on the second patch below for why.
>
>
>>From fef2bc68e36c8891780311d8869db23753c093d0 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering <at> redhat.com>
> Date: Tue, 18 Oct 2011 11:44:39 +0200
> Subject: [PATCH 1/3] tac: use only one temporary file, with multiple
>  nonseekable inputs
>
> * src/tac.c (temp_stream): New function, factored out of...
> (copy_to_temp): ...here.
> (tac_nonseekable): Don't free or fclose, now that we reuse the file.

Added this, and pushed:


Suggested by Ambrose Feinstein.
* THANKS.in: Update.


diff --git a/THANKS.in b/THANKS.in
index 23ac679..83a7864 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -37,6 +37,7 @@ Alexandre Duret-Lutz                duret_g <at> epita.fr
 Alexey Solovyov                     alekso <at> math.uu.se
 Alexey Vyskubov                     alexey <at> pippuri.mawhrin.net
 Alfred M. Szmidt                    ams <at> kemisten.nu
+Ambrose Feinstein                   ambrose <at> google.com
 Andi Kleen                          freitag <at> alancoxonachip.com
 Andre Novaes Cunha                  Andre.Cunha <at> br.global-one.net
 Andreas Frische                     andreasfrische <at> gmail.com

[Message part 3 (message/rfc822, inline)]
From: Ambrose Feinstein <ambrose <at> google.com>
To: bug-coreutils <at> gnu.org
Subject: tac fails when given multiple non-seekable inputs due to misuse of
	mkstemp()
Date: Sat, 15 Oct 2011 13:40:17 -0700
Trivial reproduction:

$ true | tac - -
tac: cannot create temporary file in `/tmp': Invalid argument

This is present in coreutils 8.14.

The cause is the way "template" is reused in copy_to_temp().  The
"XXXXXX" suffix is clobbered by the first call to mkstemp(), so the
next call returns EINVAL.

It looks like the intent is to call mkstemp() at most once and then
reuse that file; for example, record_or_unlink_tempfile() will delete
at most one file on exit.



This bug report was last modified 13 years and 223 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.