aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/regress/eqn/define/infinite.in
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2022-04-13 20:26:19 +0000
committerIngo Schwarze <schwarze@openbsd.org>2022-04-13 20:26:19 +0000
commit10729b3aa1181d3f40ecb3ba0f955f96d86eaee3 (patch)
tree23e0f420588718bcd80be303d809a557ee100167 /regress/eqn/define/infinite.in
parent4062479d6729bdfb0de4954e7a413ca3282d17cd (diff)
downloadmandoc-10729b3aa1181d3f40ecb3ba0f955f96d86eaee3.tar.gz
mandoc-10729b3aa1181d3f40ecb3ba0f955f96d86eaee3.tar.zst
mandoc-10729b3aa1181d3f40ecb3ba0f955f96d86eaee3.zip
To prevent infinite recursion while expanding eqn(7) definitions,
we must not reset the recursion counter when moving beyond the end of the *previous* expansion, but we may only do so when moving beyond the rightmost position reached by *any* expansion in the current equation. This matters because definitions can nest; consider: .EQ define inner "content" define outer "inner outer" outer .EN This endless loop was found by tb@ using afl(1). Incidentally, GNU eqn(1) also performs an infinite loop in this situation and then crashes when memory runs out, but that's not an excuse for nasty behaviour of mandoc(1). While here, consistently print the expanded content even when the expansion is finally truncated. While that is not likely to help end-users, it may help authors of eqn(7) code to understand what's going on. Besides, it sends a very clear signal that something is amiss, which was easy to miss in the past unless people enabled -W error or used -T lint.
Diffstat (limited to 'regress/eqn/define/infinite.in')
-rw-r--r--regress/eqn/define/infinite.in12
1 files changed, 10 insertions, 2 deletions
diff --git a/regress/eqn/define/infinite.in b/regress/eqn/define/infinite.in
index 420e6376..31a3f646 100644
--- a/regress/eqn/define/infinite.in
+++ b/regress/eqn/define/infinite.in
@@ -1,5 +1,5 @@
-.\" $OpenBSD: infinite.in,v 1.2 2017/07/04 14:53:23 schwarze Exp $
-.Dd $Mdocdate: July 4 2017 $
+.\" $OpenBSD: infinite.in,v 1.3 2022/04/13 20:19:18 schwarze Exp $
+.Dd $Mdocdate: April 13 2022 $
.Dt DEFINE-INFINITE 1
.Os
.Sh NAME
@@ -29,3 +29,11 @@ trailing position:
define key 'prefix key' key
.EN
eol
+.Pp
+nested expansion:
+.EQ
+define inner "content"
+define outer "inner outer"
+outer
+.EN
+eol