gbranden pushed a commit to branch master
in repository groff.
commit c0260816e7d2af31e8fb4c14dd7a8ca4253b4606
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Oct 7 11:45:22 2025 -0500
[troff]: Enable "locking" safer mode (1/3).
* src/roff/troff/input.cpp (main): New Boolean `is_safer_mode_locked`
indicates whether the `-S` command-line option has been seen. Accept
new `-S` option. If encountered, unset `want_unsafe_requests` Boolean
and set `is_safer_mode_locked`. When encountering `-U` option, throw
diagnostic and ignore it if `is_safer_mode_locked` is set.
* src/roff/troff/input.cpp (usage):
* src/roff/troff/troff.1.man (Synopsis, Options): Document it.
Illustration:
$ echo | ./build/troff -z
$ echo | ./build/troff -z -S
$ echo | ./build/troff -z -U -S
$ echo | ./build/troff -z -S -U
./build/troff: error: ignoring '-U' option; '-S' already specified
---
ChangeLog | 14 ++++++++++++++
src/roff/troff/input.cpp | 14 +++++++++++---
src/roff/troff/troff.1.man | 9 ++++++++-
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 89d3741f8..b8138862f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-10-07 G. Branden Robinson <[email protected]>
+
+ [troff]: Enable "locking" safer mode.
+
+ * src/roff/troff/input.cpp (main): New Boolean
+ `is_safer_mode_locked` indicates whether the `-S` command-line
+ option has been seen. Accept new `-S` option. If encountered,
+ unset `want_unsafe_requests` Boolean and set
+ `is_safer_mode_locked`. When encountering `-U` option, throw
+ diagnostic and ignore it if `is_safer_mode_locked` is set.
+
+ * src/roff/troff/input.cpp (usage):
+ * src/roff/troff/troff.1.man (Synopsis, Options): Document it.
+
2025-10-07 G. Branden Robinson <[email protected]>
* src/roff/groff/groff.cpp (main): Demote variable `safer_flag`
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 6d5de8016..fe4fab6d3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9223,7 +9223,7 @@ static void add_string(const char *s, string_list **p)
void usage(FILE *stream, const char *prog)
{
fprintf(stream,
-"usage: %s [-abcCEiRUz] [-d ct] [-d string=text] [-f font-family]"
+"usage: %s [-abcCEiRSUz] [-d ct] [-d string=text] [-f font-family]"
" [-F font-directory] [-I inclusion-directory] [-m macro-package]"
" [-M macro-directory] [-n page-number] [-o page-list]"
" [-r cnumeric-expression] [-r register=numeric-expression]"
@@ -9258,6 +9258,7 @@ int main(int argc, char **argv)
bool have_explicit_default_family = false;
bool have_explicit_first_page_number = false;
bool want_startup_macro_files_skipped = false;
+ bool is_safer_mode_locked = false; // made true if `-S` explicit
int next_page_number = 0; // pacify compiler
hresolution = vresolution = 1;
if (getenv("GROFF_DUMP_NODES") != 0 /* nullptr */)
@@ -9285,7 +9286,7 @@ int main(int argc, char **argv)
#define DEBUG_OPTION ""
#endif
while ((c = getopt_long(argc, argv,
- ":abcCd:Ef:F:iI:m:M:n:o:qr:Rs:tT:Uvw:W:z"
+ ":abcCd:Ef:F:iI:m:M:n:o:qr:Rs:StT:Uvw:W:z"
DEBUG_OPTION, long_options, 0))
!= EOF)
switch (c) {
@@ -9382,8 +9383,15 @@ int main(int argc, char **argv)
case 't':
// silently ignore these
break;
+ case 'S':
+ want_unsafe_requests = false;
+ is_safer_mode_locked = true;
+ break;
case 'U':
- want_unsafe_requests = true;
+ if (is_safer_mode_locked)
+ error("ignoring '-U' option; '-S' already specified");
+ else
+ want_unsafe_requests = true;
break;
#if defined(DEBUGGING)
case 'D':
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 5bffe9b03..ed6cd3029 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -49,7 +49,7 @@ typesetter and document formatter
.\" ====================================================================
.
.SY @g@troff
-.RB [ \-abcCEiRUz ]
+.RB [ \-abcCEiRSUz ]
.RB [ \-d\~\c
.IR ctext ]
.RB [ \-d\~\c
@@ -464,6 +464,13 @@ and
.
.
.TP
+.B \-S
+Enable safer mode and ignore any subsequent
+.B \-U
+option.
+.
+.
+.TP
.BI \-T\~ dev
Prepare output for device
.I dev.
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit