[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/05: [mdoc]: Fix infinite loop (Debian #411227).
From: |
G. Branden Robinson |
Subject: |
[groff] 03/05: [mdoc]: Fix infinite loop (Debian #411227). |
Date: |
Wed, 18 Nov 2020 05:42:09 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit f72ed58ba9991544c4e2dbb45fbe0710426d9f32
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Nov 18 18:32:24 2020 +1100
[mdoc]: Fix infinite loop (Debian #411227).
* tmac/mdoc/doc-common-u (doc-header): Fix infinite loop when attempting
to trim header string (like "FTP(1)") to fit when the available title
length won't allow even extreme shortening. Measure the string before
and after calling .substring on it, and break out of loop if it didn't
get shorter.
Problem dates back to at least ed63b0ae76a611b581601a1afc192f6a7367be6f
(7 July 2002), possibly as far as the Great Mdoc Rewrite of
058f72af832fc68488d33cd09ec819e5c560fa09 (23 March 2001).
One can never check loop invariants too many times...
Fixes <https://bugs.debian.org/411227>.
---
ChangeLog | 21 +++++++++++++++++++++
tmac/mdoc/doc-common-u | 9 +++++++++
2 files changed, 30 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 9818b8a..4ab623e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2020-11-18 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * tmac/mdoc/doc-common-u (doc-header): Fix infinite loop when
+ attempting to trim header string (like "FTP(1)") to fit when the
+ available title length won't allow even extreme shortening.
+ Measure the string before and after calling .substring on it,
+ and break out of loop if it didn't get shorter.
+
+ Problem dates back to at least
+ ed63b0ae76a611b581601a1afc192f6a7367be6f (7 July 2002), possibly
+ as far as the Great Mdoc Rewrite of
+ 058f72af832fc68488d33cd09ec819e5c560fa09 (23 March 2001).
+
+ One can never check loop invariants too many times...
+
+ Fixes <https://bugs.debian.org/411227>.
+
+ * tmac/tests/\
+ doc-do_not_loop_infinitely_when_shortening_headers.sh: Test it.
+ * tmac/tmac.am (tmac_TESTS): Run test.
+
+2020-11-18 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* src/roff/nroff/nroff.sh: Recognize -b and -z options and pass
them through to troff. Document them in usage message.
* src/roff/nroff/nroff.1.man: Document new -b and -z options.
diff --git a/tmac/mdoc/doc-common-u b/tmac/mdoc/doc-common-u
index 4aab7d0..1e5f6d9 100644
--- a/tmac/mdoc/doc-common-u
+++ b/tmac/mdoc/doc-common-u
@@ -928,6 +928,8 @@
.\" NS local variables:
.\" NS doc-reg-dh
.\" NS doc-reg-dh1
+.\" NS doc-hs-len
+.\" NS doc-hs-len-prev
.
.de doc-header
. ev doc-env-dh
@@ -938,9 +940,16 @@
. nr doc-reg-dh1 \w'\*[doc-caption-font2]\*[doc-volume]\f[]'
. if (\n[doc-reg-dh] + \n[doc-reg-dh1] + \n[doc-reg-dh] >= \n[.lt]) \{\
. while (\n[doc-reg-dh] + \n[doc-reg-dh1] + \n[doc-reg-dh] >= \n[.lt]) \{\
+. length doc-hs-len-prev \*[doc-header-string]
. substring doc-header-string 0 -2
+. length doc-hs-len \*[doc-header-string]
. nr doc-reg-dh \w'\*[doc-caption-font]\*[doc-header-string]\|.\|.\|.\f[]'
+. \" If header string didn't actually get shorter, stop trying.
+. if (\n[doc-hs-len-prev] <= \n[doc-hs-len]) \
+. break
. \}
+. rr doc-hs-len
+. rr doc-hs-len-prev
. as doc-header-string "\|.\|.\|.
. \}
. tl
\*[doc-caption-font]\*[doc-header-string]\f[]\*[doc-caption-font2]\*[doc-volume]\f[]\*[doc-caption-font]\*[doc-header-string]\f[]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/05: [mdoc]: Fix infinite loop (Debian #411227).,
G. Branden Robinson <=