From 4c124f70e22deecce385bd0164cabbc6e1946fe0 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 17 Dec 2019 19:24:59 +0000 Subject: avoid closing already-closed \openout file git-svn-id: svn://tug.org/texlive/trunk@53155 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/ChangeLog | 5 +++++ Build/source/texk/web2c/Makefile.in | 4 ++-- Build/source/texk/web2c/am/texmf.am | 8 +++++--- Build/source/texk/web2c/tests/tex-closeout.test | 19 +++++++++++++++++++ Build/source/texk/web2c/tex.ch | 11 ++++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100755 Build/source/texk/web2c/tests/tex-closeout.test (limited to 'Build/source') diff --git a/Build/source/texk/web2c/ChangeLog b/Build/source/texk/web2c/ChangeLog index dcf4334008a..f43e8c77bb4 100644 --- a/Build/source/texk/web2c/ChangeLog +++ b/Build/source/texk/web2c/ChangeLog @@ -1,5 +1,10 @@ 2019-12-17 Karl Berry + * tex.ch (out_what [1374]): always set write_open[j]:=false + if we a_close(write_file[j]), not worrying about the subtype. + * tests/tex-closeout.test: new test. + * am/texmf.am (tex_tests): add it. + * mftraptest.test, triptest.test: rm the .base/.fmt file before remaking it, so we can't find one left over from a previous run. diff --git a/Build/source/texk/web2c/Makefile.in b/Build/source/texk/web2c/Makefile.in index 492d85bcc89..bd3c7cd3123 100644 --- a/Build/source/texk/web2c/Makefile.in +++ b/Build/source/texk/web2c/Makefile.in @@ -3585,7 +3585,7 @@ tex_ch_srcs = \ # TeX tests # -tex_tests = triptest.test tests/write18-quote-test.pl +tex_tests = triptest.test tests/write18-quote-test.pl tests/tex-closeout.test call_mf_CPPFLAGS = -DEXEPROG=\"mf.exe\" nodist_call_mf_SOURCES = callexe.c call_mf_LDADD = @@ -19068,7 +19068,7 @@ tex-tangle: tangle$(EXEEXT) tex.web tex-final.ch tangle-sh tex-final.ch: tie$(EXEEXT) $(tex_ch_srcs) $(tie_c) $(tex_ch_srcs) triptest.log: tex$(EXEEXT) dvitype$(EXEEXT) pltotf$(EXEEXT) tftopl$(EXEEXT) -tests/write18-quote-test.log: tex$(EXEEXT) +tests/write18-quote-test.log tests/tex-closeout.test: tex$(EXEEXT) trip.diffs: tex$(EXEEXT) dvitype$(EXEEXT) pltotf$(EXEEXT) tftopl$(EXEEXT) $(triptrap_diffs) $@ diff --git a/Build/source/texk/web2c/am/texmf.am b/Build/source/texk/web2c/am/texmf.am index 2ec67cbd27a..cb8dde2b4ec 100644 --- a/Build/source/texk/web2c/am/texmf.am +++ b/Build/source/texk/web2c/am/texmf.am @@ -1,6 +1,8 @@ +## $Id$ ## texk/web2c/am/texmf.am: Makefile fragment for TeX and MF. ## -## Copyright (C) 2009-2015 Peter Breitenlohner +## Copyright 2015-2019 Karl Berry +## Copyright 2009-2015 Peter Breitenlohner ## You may freely use, modify and/or distribute this file. ## Common for MF and TeX @@ -73,9 +75,9 @@ DISTCLEANFILES += $(nodist_tex_SOURCES) tex-final.ch tex-web2c \ # TeX tests # -tex_tests = triptest.test tests/write18-quote-test.pl +tex_tests = triptest.test tests/write18-quote-test.pl tests/tex-closeout.test triptest.log: tex$(EXEEXT) dvitype$(EXEEXT) pltotf$(EXEEXT) tftopl$(EXEEXT) -tests/write18-quote-test.log: tex$(EXEEXT) +tests/write18-quote-test.log tests/tex-closeout.test: tex$(EXEEXT) EXTRA_DIST += $(tex_tests) EXTRA_DIST += tests/write18-quote.tex if TEX diff --git a/Build/source/texk/web2c/tests/tex-closeout.test b/Build/source/texk/web2c/tests/tex-closeout.test new file mode 100755 index 00000000000..c510313fa61 --- /dev/null +++ b/Build/source/texk/web2c/tests/tex-closeout.test @@ -0,0 +1,19 @@ +#! /bin/sh -vx +# $Id$ +# Copyright 2019 Karl Berry +# You may freely use, modify and/or distribute this file. + +# in case we're invoked standalone instead of from make. +test -z "$srcdir" && srcdir=`cd \`dirname $0\`/.. && pwd` # web2c/ +TEXMFCNF=$srcdir/../kpathsea; export TEXMFCNF + +# Resulted in a double free with glibc on x86_64-linux. +fail=2 +./tex -ini '\batchmode \immediate\openout1=b \openout1=/tmp/a \end' + +# If TeX crashed, we won't get here. The exit status will be something +# like 134 on GNU/Linux, but we don't want to rely on that. +fail=0 + +exit $fail + diff --git a/Build/source/texk/web2c/tex.ch b/Build/source/texk/web2c/tex.ch index 6c4fadf8357..a45b99198c2 100644 --- a/Build/source/texk/web2c/tex.ch +++ b/Build/source/texk/web2c/tex.ch @@ -4381,7 +4381,16 @@ var j:small_number; {write stream number} @!old_setting:0..max_selector; @z -@x [53.1374] Disallow certain \openout filenames, and log results. +@x [53.1374] + else begin if write_open[j] then a_close(write_file[j]); + if subtype(p)=close_node then write_open[j]:=false +@y + else begin if write_open[j] then begin a_close(write_file[j]); + write_open[j]:=false; end; + if subtype(p)=close_node then do_nothing {already closed} +@z + +@x [still 53.1374] Disallow certain \openout filenames, and log results. while not a_open_out(write_file[j]) do prompt_file_name("output file name",".tex"); write_open[j]:=true; -- cgit v1.2.3