[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 111/115: [troff]: Validate a font family before using it.
From: |
G. Branden Robinson |
Subject: |
[groff] 111/115: [troff]: Validate a font family before using it. |
Date: |
Thu, 1 Jun 2023 10:46:19 -0400 (EDT) |
gbranden pushed a commit to branch branden-2022-06-01
in repository groff.
commit 1fea0c142fae929cce003d6e529e000687149735
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu May 25 05:35:25 2023 -0500
[troff]: Validate a font family before using it.
* src/roff/troff/env.cpp (is_family_valid): New function checks for all
text styles (R, I, B, BI) and returns true only if the given family
supports them all.
(family_change): Call `is_family_valid()` on given argument. If
invalid, throw diagnostic and ignore `fam` request.
* src/roff/troff/env.h (is_family_valid): Declare; make visible.
* src/roff/troff/input.cpp (main): Call `is_family_valid()` on `-f`
option argument. Its invalidity is a fatal error.
Fixes <https://savannah.gnu.org/bugs/?64115>. Thanks to Dave
Kemper for the report.
Tested with:
$ echo | ./build/test-groff -fZD -z
troff: fatal error: 'ZD' is not a valid font family
$ echo | ./build/test-groff -fH -z
$ nl ./EXPERIMENTS/validate-family.groff
1 .tm .fam=\n[.fam]
2 .fam H
3 .tm .fam=\n[.fam]
4 .fam
5 .tm .fam=\n[.fam]
6 .fam ZD
7 .fam BOGUS
8 .tm .fam=\n[.fam]
9 .fam
10 .tm .fam=\n[.fam]
$ ./build/test-groff ./EXPERIMENTS/validate-family.groff
.fam=T
.fam=H
.fam=T
troff:./EXPERIMENTS/validate-family.groff:6: error: 'ZD' is not a valid
font family
troff:./EXPERIMENTS/validate-family.groff:7: error: 'BOGUS' is not a valid
font family
.fam=T
.fam=H
---
ChangeLog | 16 ++++++++++++++++
src/roff/troff/env.cpp | 20 ++++++++++++++++++++
src/roff/troff/env.h | 1 +
src/roff/troff/input.cpp | 3 +++
4 files changed, 40 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 364cff1ee..424bd44d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-05-25 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [troff]: Validate a font family before trying to use it.
+
+ * src/roff/troff/env.cpp (is_family_valid): New function checks
+ for all text styles (R, I, B, BI) and returns true only if the
+ given family supports them all.
+ (family_change): Call `is_family_valid()` on given argument.
+ If invalid, throw diagnostic and ignore `fam` request.
+ * src/roff/troff/env.h (is_family_valid): Declare; make visible.
+ * src/roff/troff/input.cpp (main): Call `is_family_valid()` on
+ `-f` option argument. Its invalidity is a fatal error.
+
+ Fixes <https://savannah.gnu.org/bugs/?64115>. Thanks to Dave
+ Kemper for the report.
+
2023-05-25 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/env.h (read_hyphen_file): Drop relic prototype
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 4c64273ef..13dd10d09 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1256,9 +1256,29 @@ void font_change()
skip_line();
}
+bool is_family_valid(const char *fam)
+{
+ // std::vector<const char *> styles{"R", "I", "B", "BI"}; // C++11
+ const size_t nstyles = 4;
+ const char *st[nstyles] = { "R", "I", "B", "BI" };
+ std::vector<const char *> styles(st, (st + nstyles));
+ std::vector<const char *>::iterator style;
+ // for (auto style : styles) // C++11
+ for (style = styles.begin(); style != styles.end(); style++)
+ if (!check_font(fam, *style))
+ return false;
+ return true;
+}
+
void family_change()
{
symbol s = get_name();
+ if (s != 0 /* nullptr */)
+ if (!is_family_valid(s.contents())) {
+ error("'%1' is not a valid font family", s.contents());
+ skip_line();
+ return;
+ }
curenv->set_family(s);
skip_line();
}
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index d98941914..8382d11ea 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -408,6 +408,7 @@ extern void pop_env();
extern void push_env(int);
void init_environments();
+bool is_family_valid(const char *);
extern double spread_limit;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index cbb8b1ca3..56c20f3eb 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8333,6 +8333,9 @@ int main(int argc, char **argv)
warning(WARN_FONT, "cannot mount font '%1' directed by 'DESC'"
" file for device '%2'", font::font_name_table[i],
device);
+ if (fflag && !(is_family_valid(default_family.contents())))
+ fatal("'%1' is not a valid font family",
+ default_family.contents());
curdiv = topdiv = new top_level_diversion;
if (nflag)
topdiv->set_next_page_number(next_page_number);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 111/115: [troff]: Validate a font family before using it.,
G. Branden Robinson <=