gbranden pushed a commit to branch master
in repository groff.
commit 3a1b01474d5590131e7ab0a54a32c1c3fec98522
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Oct 7 13:06:25 2025 -0500
[groff]: Enable "locking" safer mode (3/3).
* src/roff/groff/groff.cpp (main): Add new Boolean variables
`is_safer_mode_locked` and `want_unsafe_mode`. Drop unused variable
`want_safer_mode`. If the `-S` flag is encountered, "lock" safer mode
and unset `want_unsafe_mode`. If the `-U` flag is encountered and
safer mode is locked, throw an error diagnostic. Otherwise, continue
as before. If safer mode has been explicitly requested, supply pic(1)
and troff(1) with the `-S` option.
* src/roff/groff/groff.1.man (groff-specific options)
(Transparent options): Document it.
---
ChangeLog | 16 ++++++++++++++++
src/roff/groff/groff.1.man | 25 +++++++++++++++++++++----
src/roff/groff/groff.cpp | 17 +++++++++++++----
3 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 168b9fbba..d3ba224e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2025-10-07 G. Branden Robinson <[email protected]>
+
+ [groff]: Enable "locking" safer mode (3/3).
+
+ * src/roff/groff/groff.cpp (main): Add new Boolean variables
+ `is_safer_mode_locked` and `want_unsafe_mode`. Drop unused
+ variable `want_safer_mode`. If the `-S` flag is encountered,
+ "lock" safer mode and unset `want_unsafe_mode`. If the `-U`
+ flag is encountered and safer mode is locked, throw an error
+ diagnostic. Otherwise, continue as before. If safer mode has
+ been explicitly requested, supply pic(1) and troff(1) with the
+ `-S` option.
+
+ * src/roff/groff/groff.1.man (groff-specific options)
+ (Transparent options): Document it.
+
2025-10-07 G. Branden Robinson <[email protected]>
[pic]: Enable "locking" safer mode (2/3).
diff --git a/src/roff/groff/groff.1.man b/src/roff/groff/groff.1.man
index b2a07c901..25fd93019 100644
--- a/src/roff/groff/groff.1.man
+++ b/src/roff/groff/groff.1.man
@@ -435,12 +435,17 @@ preprocessor.
.
.TP
.B \-S
-Operate in \[lq]safer\[rq] mode;
-see
+Enable safer mode and ignore any subsequent
.B \-U
-below for its opposite.
+option.
.
-Safer mode is enabled by default.
+.I groff
+passes the
+.B \-S
+option to
+.MR @g@pic @MAN1EXT@
+and
+.MR @g@troff @MAN1EXT@ .
.
.
.TP
@@ -667,6 +672,18 @@ Define register.
.
.
.TP
+.B \-S
+Enable safer mode and ignore any subsequent
+.B \-U
+option.
+.
+.
+.TP
+.B \-U
+Operate in unsafe mode.
+.
+.
+.TP
.BI \-w\~ cat
.TQ
.BI \-W\~ cat
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index 9da763a98..aafe66021 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -167,7 +167,8 @@ int main(int argc, char **argv)
int iflag = 0;
int Xflag = 0;
int oflag = 0;
- bool want_safer_mode = true;
+ bool is_safer_mode_locked = false; // made true if `-S` explicit
+ bool want_unsafe_mode = true;
int is_xhtml = 0;
int eflag = 0;
int need_pic = 0;
@@ -308,10 +309,14 @@ int main(int argc, char **argv)
commands[TROFF_INDEX].append_arg(buf);
break;
case 'S':
- want_safer_mode = true;
+ is_safer_mode_locked = true;
+ want_unsafe_mode = false;
break;
case 'U':
- want_safer_mode = false;
+ if (is_safer_mode_locked)
+ warning("ignoring '-U' option; '-S' already specified");
+ else
+ want_unsafe_mode = true;
break;
case 'T':
if (strcmp(optarg, "xhtml") == 0) {
@@ -397,7 +402,11 @@ int main(int argc, char **argv)
if (!Kflag && *encoding)
commands[PRECONV_INDEX].append_arg("-e", encoding);
}
- if (!want_safer_mode) {
+ if (is_safer_mode_locked) {
+ commands[TROFF_INDEX].insert_arg("-S");
+ commands[PIC_INDEX].append_arg("-S");
+ }
+ else if (want_unsafe_mode) {
commands[TROFF_INDEX].insert_arg("-U");
commands[PIC_INDEX].append_arg("-U");
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit