gbranden pushed a commit to branch master
in repository groff.

commit eb216caf1a0ee88f9de6593031dd42c4f19ea3d4
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Apr 12 07:52:58 2025 -0500

    [troff]: Fix `write` request SEGV.
    
    * src/roff/troff/input.cpp (do_write_request): Fix SEGV when attempting
      to write to a stream that doesn't exist.
    
    $ echo '.write foo bar' | groff -U
    groff: error: troff: Segmentation fault (core dumped)
    
    Continues commit 6d32f2492e, 13 September.
---
 ChangeLog                | 5 +++++
 src/roff/troff/input.cpp | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index f1e908aae..e985f4244 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-04-12  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (do_write_request): Fix SEGV when
+       attempting to write to a stream that doesn't exist.
+
 2025-04-12  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (macro_header::json_dump): If a macro
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 7a7d49a0e..019de8783 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7784,6 +7784,13 @@ void do_write_request(int newline)
     return;
   }
   grostream *grost = (grostream *)stream_dictionary.lookup(stream);
+  if (0 /* nullptr */ == grost) {
+    error("cannot write to nonexistent stream '%1'", stream.contents());
+    skip_line();
+    return;
+  }
+  // Invariant: if the groff stream exists, the backing C stream must.
+  assert(grost->file != 0 /* nullptr */);
   FILE *fp = grost->file;
   if (0 /* nullptr */ == fp) {
     error("cannot write to nonexistent stream '%1'", stream.contents());

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to