From 22999697b81acf3e8683c95c310a36926e7af96f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 13 Aug 2008 20:53:12 +0200 Subject: mktemp, sort, tac: don't use undefined after mkstemp failure When mkstemp fails, the template buffer may have undefined contents, so we must not print it. * src/sort.c (create_temp_file): Use temp_dir, not "file" when diagnosing failed mkstemp, because "file" may be undefined. * tests/misc/sort-merge: Adjust for new expected output. Jeph Cowan and Ralf Wildenhues reported the test failure: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/14235/focus=14257 * src/tac.c (copy_to_temp): Don't use template buffer after failed mkstemp call, since its contents may be undefined. * tests/misc/tac (pipe-bad-tmpdir): New test for the above. * src/mktemp.c (main): Save a copy of the template string, solely for use in case mkstemp fails. * tests/misc/mktemp (pipe-bad-tmpdir): New test for the above. --- tests/misc/tac | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/misc/tac') diff --git a/tests/misc/tac b/tests/misc/tac index 2f9981d49..9995357ab 100755 --- a/tests/misc/tac +++ b/tests/misc/tac @@ -22,6 +22,8 @@ my $prog = 'tac'; # Turn off localization of executable's output. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; +my $bad_dir = 'no/such/dir'; + my @Tests = ( ['segfault', '-r', {IN=>"a\n"}, {IN=>"b\n"}, {OUT=>"a\nb\n"}], @@ -58,6 +60,13 @@ my @Tests = ['opt-br2', qw(-b -r -s '\._+'), {IN=>".__x.___y.____z._1._2.__3.___4"}, {OUT=>".___4.__3._2._1.____z.___y.__x"}], + + ['pipe-bad-tmpdir', + {ENV => "TMPDIR=$bad_dir"}, + {IN_PIPE => "a\n"}, + {ERR_SUBST => "s,`$bad_dir': .*,...,"}, + {ERR => "$prog: cannot create temporary file in ...\n"}, + {EXIT => 1}], ); @Tests = triple_test \@Tests; -- cgit v1.2.3-54-g00ecf