diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2024-02-28 04:19:31 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2024-02-28 04:19:31 +0000 |
commit | 829a29bbc11332132efc6c3dc5f99c07f9fac28b (patch) | |
tree | 2f95f5f818d50aaf74a161a50b6d077a3ebaf8c6 | |
parent | 7bd5677ef5e998377b2886bcb14b791cf2171aab (diff) |
apply unbalanced-braces.ch for [eu]ptex
git-svn-id: svn://tug.org/texlive/trunk@70222 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/web2c/ChangeLog | 11 | ||||
-rw-r--r-- | Build/source/texk/web2c/Makefile.in | 4 | ||||
-rw-r--r-- | Build/source/texk/web2c/eptexdir/am/eptex.am | 1 | ||||
-rw-r--r-- | Build/source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch | 141 | ||||
-rw-r--r-- | Build/source/texk/web2c/euptexdir/am/euptex.am | 1 | ||||
-rw-r--r-- | Build/source/texk/web2c/ptexdir/am/ptex.am | 1 | ||||
-rw-r--r-- | Build/source/texk/web2c/uptexdir/am/uptex.am | 1 |
7 files changed, 160 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/ChangeLog b/Build/source/texk/web2c/ChangeLog index 7d83eed3476..33fe6d3a32f 100644 --- a/Build/source/texk/web2c/ChangeLog +++ b/Build/source/texk/web2c/ChangeLog @@ -1,3 +1,14 @@ +2024-02-28 Akira Kakuto <kakuto@jcom.zaq.ne.jp> + + * eptexdir/unbalanced-braces-eptex.ch: avoid crashing with devious + uses of \output and \write braces. Slightly modified one for + eptex and euptex. + * eptexdir/am/eptex.am (eptex_ch_srcs), + * euptexdir/am/euptex.am (euptex_ch_srcs) : include + eptexdir/unbalanced-braces-eptex.ch. + * ptexdir/am/ptex.am (ptex_ch_srcs), + * uptexdir/am/uptex.am (uptex_ch_srcs): include unbalanced-braces.ch. + 2024-02-26 Karl Berry <karl@freefriends.org> * unbalanced-braces.ch: avoid crashing with devious uses of diff --git a/Build/source/texk/web2c/Makefile.in b/Build/source/texk/web2c/Makefile.in index a2f59fd4515..2ebe898788f 100644 --- a/Build/source/texk/web2c/Makefile.in +++ b/Build/source/texk/web2c/Makefile.in @@ -4424,6 +4424,7 @@ ptex_web_srcs = \ ptex_ch_srcs = \ ptexdir/ptex-base.ch \ + unbalanced-braces.ch \ $(ptex_ch_synctex) \ tex-binpool.ch @@ -4474,6 +4475,7 @@ eptex_ch_srcs = \ eptexdir/fam256.ch \ eptexdir/pdfutils.ch \ eptexdir/suppresserrors.ch \ + eptexdir/unbalanced-braces-eptex.ch \ eptexdir/char-warning-eptex.ch \ tex-binpool.ch @@ -4516,6 +4518,7 @@ uptex_web_srcs = \ uptex_ch_srcs = \ uptexdir/ptex-base.ch \ + unbalanced-braces.ch \ uptexdir/uptex-m.ch \ $(uptex_ch_synctex) \ tex-binpool.ch @@ -4601,6 +4604,7 @@ euptex_ch_srcs = \ euptexdir/pdfutils.ch \ euptexdir/pdfstrcmp-eup-post.ch \ euptexdir/suppresserrors.ch \ + eptexdir/unbalanced-braces-eptex.ch \ euptexdir/char-warning-eptex.ch \ tex-binpool.ch diff --git a/Build/source/texk/web2c/eptexdir/am/eptex.am b/Build/source/texk/web2c/eptexdir/am/eptex.am index 6bb6e996d2a..8ff94d61068 100644 --- a/Build/source/texk/web2c/eptexdir/am/eptex.am +++ b/Build/source/texk/web2c/eptexdir/am/eptex.am @@ -77,6 +77,7 @@ eptex_ch_srcs = \ eptexdir/fam256.ch \ eptexdir/pdfutils.ch \ eptexdir/suppresserrors.ch \ + eptexdir/unbalanced-braces-eptex.ch \ eptexdir/char-warning-eptex.ch \ tex-binpool.ch diff --git a/Build/source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch b/Build/source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch new file mode 100644 index 00000000000..ae9fd94e2f1 --- /dev/null +++ b/Build/source/texk/web2c/eptexdir/unbalanced-braces-eptex.ch @@ -0,0 +1,141 @@ +% unbalanced-braces-eptex.ch +% Fix overrun/underrun of \write and \output. David Fuchs, 2024. +% Public domain. +% +% Changes for full defense against over-running (or under-running) +% an \output or \write and ending up in all sorts of ill-defined +% trouble. (Including the case of \output=\toks with no braces.) +% +% For some problematic input files, see tests/unbalanced-braces.test +% (not a runnable test). +% +% The idea is that when it's time to run/evaluate each \output or \write, +% they have to come to an end exactly as expected: at the right brace that +% came from when they were first scanned to begin with; no amount of +% monkey business with "funny braces" or \noexpand or \expandafter or \let +% or whatever other trick you can think of should be able to get around +% it. And you can't get away with going even one token past where you were +% supposed to stop. +% +% To reiterate, fatal errors from this result in the terminal show just: +% ! Emergency stop. +% with no details on what/why. You have to look in the .log file for +% the (terse) specifics: +% Unbalanced output routine +% +% It's rather draconian, calling fatal_error when there's a problem, +% but users really have no business trying to get anywhere near this +% sort of thing on purpose. I sure hope nobody has found any use for +% such undefined behaviors. + +% The changes assume locnull-optimize.ch has been applied. Unfortunately +% the semantically-related changes have to be broken up to apply in +% tex.web order. + +% emacs-page +%% Catch extra left braces in \output right when finished scanning it. +% +@x [23.324] l.7000 p.B139 + if token_type=macro then {parameters must be flushed} + while param_ptr>param_start do + begin decr(param_ptr); + flush_list(param_stack[param_ptr]); + end; +@y + if token_type=macro then {parameters must be flushed} + while param_ptr>param_start do + begin decr(param_ptr); + flush_list(param_stack[param_ptr]); + end + else if (token_type=output_text)and(output_active) then + fatal_error("Unbalanced output routine"); +@.Unbalanced output routine@> +@z + +%% Catch extra right braces in the \output routine. +% <Resume the page builder...> tried, but needs to be more robust against +% a backed-up right (funny) brace in the middle of \output masquerading +% as the end-of-\output right brace. +% +% Reorder these so that end_token_list sees output_active=false. +% 1) In back_input: +@x [23.325] l.7025 p.B139 +begin while (loc=null)and(token_type<>v_template) do + end_token_list; {conserve stack space} +@y +begin while (loc=null)and(token_type<>v_template) + and(token_type<>output_text) do + end_token_list; {conserve stack space} +@z + +%% Catch extra left braces finishing scanning a \write_text. +% +% In <Input from token list...> don't allow end_write while we're +% still scanning through the write_text. +@x [24.357] l.7488 p.B150 + else if suppress_outer_error=0 then check_outer_validity; +@y + else if suppress_outer_error=0 then + begin + if (cur_cs=end_write)and(mode=0) then + fatal_error("Unbalanced write command"); + check_outer_validity; + end; +@z + +%% Returning to catching extra right braces. +% +% 2) In <Feed the macro body and its parameters to the scanner>: +@x [25.390] l.7983 p.B161 +while (loc=null)and(token_type<>v_template) do + end_token_list; {conserve stack space} +@y +while (loc=null)and(token_type<>v_template) + and(token_type<>output_text) do + end_token_list; {conserve stack space} +@z + +% We know we've just scanned a right brace that seems to be the end +% of the \output routine. But maybe it had been backed-up over, +% and we've lost the output_text in the call to back_input. So, +% the checking gets sloppy. But now we're sure to keep the +% (finished) output_text level around, so we can always check +% that we were just finished with it, so it's where the brace +% came from. + +% In <Resume the page builder after an output routine has come to an end>: +@x [45.1026] l.19938 p.B432 +begin if (loc<>null) or + ((token_type<>output_text)and(token_type<>backed_up)) then + @<Recover from an unbalanced output routine@>; +@y +begin + while (state=token_list)and(loc=null)and(token_type=backed_up) do + end_token_list; {output-ending brace may have been backed-up} + if (state<>token_list)or(loc<>null)or(token_type<>output_text) then + @<Recover from an unbalanced output routine@>; +@z + +% In <Resume the page builder after an output routine has come to an end>: +@x [45.1026] l.19941 p.B432 +end_token_list; {conserve stack space in case more outputs are triggered} +end_graf; unsave; output_active:=false; insert_penalties:=0;@/ +@y +end_graf; unsave; output_active:=false; insert_penalties:=0;@/ +end_token_list; {conserve stack space in case more outputs are triggered} +@z + +% <Expand macros in the token list and...> had set mode:=0 while +% expanding the \write token list. + +% Reorder these statements so that the final get_token that's supposed to +% scan off the end_write_token will have mode<>0 if everything lined up: +@x [53.1371] l.24884 p.B546 +get_token;@+if cur_tok<>end_write_token then + @<Recover from an unbalanced write command@>; +mode:=old_mode; +@y +mode:=old_mode; +get_token;@+if cur_tok<>end_write_token then + @<Recover from an unbalanced write command@>; +@z diff --git a/Build/source/texk/web2c/euptexdir/am/euptex.am b/Build/source/texk/web2c/euptexdir/am/euptex.am index 31e31e04bb7..a4d83023adf 100644 --- a/Build/source/texk/web2c/euptexdir/am/euptex.am +++ b/Build/source/texk/web2c/euptexdir/am/euptex.am @@ -83,6 +83,7 @@ euptex_ch_srcs = \ euptexdir/pdfutils.ch \ euptexdir/pdfstrcmp-eup-post.ch \ euptexdir/suppresserrors.ch \ + eptexdir/unbalanced-braces-eptex.ch \ euptexdir/char-warning-eptex.ch \ tex-binpool.ch diff --git a/Build/source/texk/web2c/ptexdir/am/ptex.am b/Build/source/texk/web2c/ptexdir/am/ptex.am index afda7181fba..ee8117c6800 100644 --- a/Build/source/texk/web2c/ptexdir/am/ptex.am +++ b/Build/source/texk/web2c/ptexdir/am/ptex.am @@ -84,6 +84,7 @@ ptex.ch: tie$(EXEEXT) ptex.web $(ptex_ch_srcs) $(tie_c) ptex.web $(ptex_ch_srcs) ptex_ch_srcs = \ ptexdir/ptex-base.ch \ + unbalanced-braces.ch \ $(ptex_ch_synctex) \ tex-binpool.ch diff --git a/Build/source/texk/web2c/uptexdir/am/uptex.am b/Build/source/texk/web2c/uptexdir/am/uptex.am index 8264e41d964..4df5f0850b2 100644 --- a/Build/source/texk/web2c/uptexdir/am/uptex.am +++ b/Build/source/texk/web2c/uptexdir/am/uptex.am @@ -78,6 +78,7 @@ uptex.ch: tie$(EXEEXT) uptex.web $(uptex_ch_srcs) $(tie_c) uptex.web $(uptex_ch_srcs) uptex_ch_srcs = \ uptexdir/ptex-base.ch \ + unbalanced-braces.ch \ uptexdir/uptex-m.ch \ $(uptex_ch_synctex) \ tex-binpool.ch |