gbranden pushed a commit to branch master
in repository groff.
commit cf06e38933dd77e90d898890259a069aa9f1ce59
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Sep 21 22:15:32 2024 -0500
[troff]: Fix SEGV I introduced 8 days ago.
* src/roff/troff/input.cpp (close_stream): Handle being given a
nonexistent stream to close. Prevents null pointer dereference.
Continues 6d32f2492e, 13 September.
---
ChangeLog | 6 ++++++
src/roff/troff/input.cpp | 12 ++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ce16fb55f..ac6fd1094 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-21 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (close_stream): Handle being given a
+ nonexistent stream to close. Prevents null pointer dereference.
+ Continues 6d32f2492e, 13 September.
+
2024-09-17 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (open_file): Fix unsafe-mode SEGV
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 6de8078c6..00dc10ebb 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7335,9 +7335,17 @@ static void opena_request() // .opena
static void close_stream(symbol &stream)
{
assert(!stream.is_null());
+ bool is_valid = false;
+ FILE *fp = 0 /* nullptr */;
grostream *grost = (grostream *)stream_dictionary.lookup(stream);
- FILE *fp = grost->file;
- if (0 /* nullptr */ == fp) {
+ if (grost != 0 /* nullptr */) {
+ fp = grost->file;
+ // We shouldn't have stored a null pointer in the first place.
+ assert(fp != 0 /* nullptr */);
+ if (fp != 0 /* nullptr */)
+ is_valid = true;
+ }
+ if (!is_valid) {
error("cannot close nonexistent stream '%1'", stream.contents());
return;
}
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit