texlive[74585] Build/source/texk/web2c: [WEAVE] Prevent get_line()

commits+ascherer at tug.org commits+ascherer at tug.org
Wed Mar 12 16:10:19 CET 2025


Revision: 74585
          https://tug.org/svn/texlive?view=revision&revision=74585
Author:   ascherer
Date:     2025-03-12 16:10:19 +0100 (Wed, 12 Mar 2025)
Log Message:
-----------
[WEAVE] Prevent get_line() when parsing module name.

In message <https://tug.org/pipermail/tex-k/2025-March/004166.html>
Benjamin Gray presents a MWE that crashes WEAVE with a segfault.

This commit incorporates his suggested patch in WEAVE.CH. New material
is placed in suitable modules of part 17 and variable in_module_name is,
of course, made of type 'boolean'.

Note that the original WEAVE.WEB does not crash and burn when compiled
with the FPC Pascal environment. However, the C transpilation in TeX
Live leads to catastrophe.

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/ChangeLog
    trunk/Build/source/texk/web2c/weave.ch

Modified: trunk/Build/source/texk/web2c/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/ChangeLog	2025-03-12 11:54:23 UTC (rev 74584)
+++ trunk/Build/source/texk/web2c/ChangeLog	2025-03-12 15:10:19 UTC (rev 74585)
@@ -1,5 +1,11 @@
 2025-03-12  Andreas Scherer  <https://ascherer.github.io>
 
+	* weave.ch: Prevent get_line() when parsing module name.
+	Report and patch from Benjamin Gray
+	(https://tug.org/pipermail/tex-k/2025-March/004166.html).
+
+2025-03-12  Andreas Scherer  <https://ascherer.github.io>
+
 	* weave.ch: Parse and reject verbatim in TeX part.
 	Report and patch from Benjamin Gray
 	(https://tug.org/pipermail/tex-k/2025-March/004169.html).

Modified: trunk/Build/source/texk/web2c/weave.ch
===================================================================
--- trunk/Build/source/texk/web2c/weave.ch	2025-03-12 11:54:23 UTC (rev 74584)
+++ trunk/Build/source/texk/web2c/weave.ch	2025-03-12 15:10:19 UTC (rev 74585)
@@ -323,6 +323,36 @@
 if (reserved(p)or(byte_start[p]+1=byte_start[p+ww]))and
 @z
 
+ at x [9.82] l.1448 - Guard against get_line() when parsing a module name
+ at p procedure get_line; {inputs the next line}
+label restart;
+begin restart:if changing then
+  @<Read from |change_file| and maybe turn off |changing|@>;
+if not changing then
+  begin @<Read from |web_file| and maybe turn on |changing|@>;
+  if changing then goto restart;
+  end;
+loc:=0; buffer[limit]:=" ";
+end;
+ at y
+ at p procedure get_line; {inputs the next line}
+label restart;
+begin
+  if in_module_name then begin
+    err_print('! Call to get_line when parsing a module name');
+    loc:=limit; {Reset to the |'|'| at the end of the line}
+  end else
+begin restart:if changing then
+  @<Read from |change_file| and maybe turn off |changing|@>;
+if not changing then
+  begin @<Read from |web_file| and maybe turn on |changing|@>;
+  if changing then goto restart;
+  end;
+loc:=0; buffer[limit]:=" ";
+end;
+end;
+ at z
+
 @x [12.124] l.2199
 `\.{\\input webmac}'.
 @.\\input webmac@>
@@ -529,6 +559,37 @@
 @<Append \(|termin...@>=
 @z
 
+ at x [17.202] l.3913 - Guard against get_line() while parsing module name
+@ @d cur_end==cur_state.end_field {current ending location in |tok_mem|}
+ at y
+@ The module name Pascal parser re-uses the buffer and |get_next|
+infrastructure. However we don't want |get_next| to cause the next source line
+to be read with |get_line|, so we set a flag to trigger an error and recover if
+this happens.
+
+ at d cur_end==cur_state.end_field {current ending location in |tok_mem|}
+ at z
+ at x [17.202] l.3919 - Guard against get_line() while parsing module name
+@!cur_state:output_state; {|cur_end|, |cur_tok|, |cur_mode|}
+ at y
+@!in_module_name:boolean; {are we scanning a module name?}
+@!cur_state:output_state; {|cur_end|, |cur_tok|, |cur_mode|}
+ at z
+
+ at x [17.203] l.3925 - Guard against get_line() while parsing module name
+@ @<Set init...@>=stat max_stack_ptr:=0;@+tats
+ at y
+@ @<Set init...@>=@!in_module_name:=false;
+stat max_stack_ptr:=0;@+tats
+ at z
+
+ at x [17.214] l.4170 - Guard against get_line() while parsing module name
+    buffer[limit]:="|"; output_Pascal;
+ at y
+    buffer[limit]:="|";
+    in_module_name:=true; output_Pascal; in_module_name:=false;
+ at z
+
 @x [18.222] l.4285 - Reject verbatim in TeX part
 TeX_string,xref_roman,xref_wildcard,xref_typewriter,module_name:
   begin loc:=loc-2; next_control:=get_next; {skip to \.{@@>}}



More information about the tex-live-commits mailing list.