[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 23/24: [troff]: Avoid potentially misleading diagnostic.
From: |
G. Branden Robinson |
Subject: |
[groff] 23/24: [troff]: Avoid potentially misleading diagnostic. |
Date: |
Sun, 10 Nov 2024 14:56:24 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 5ff8d65c82593b9cc38b84cf36ab121711d64090
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Nov 10 12:48:42 2024 -0600
[troff]: Avoid potentially misleading diagnostic.
* src/roff/troff/input.cpp (diagnose_invalid_identifier): Avoid
potentially reporting stale token description in diagnostic message,
using same technique as commit 1277744e72, 20 August. I was unable to
verify that the token description really is stale, however. It might
not be, since it is lazily computed and the class's `description()`
member function is not called in the interim, but I also could not
demonstrate to myself that the relevant diagnostic message is
reachable. Use strdup() to copy the token description (grabbing ~30
bytes from the heap) and free that storage later just in case.
---
ChangeLog | 13 +++++++++++++
src/roff/troff/input.cpp | 6 +++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 5ef58af19..c3cefd5be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-11-10 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/roff/troff/input.cpp (diagnose_invalid_identifier): Avoid
+ potentially reporting stale token description in diagnostic
+ message, using same technique as commit 1277744e72, 20 August.
+ I was unable to verify that the token description really is
+ stale, however. It might not be, since it is lazily computed
+ and the class's `description()` member function is not called in
+ the interim, but I also could not demonstrate to myself that the
+ relevant diagnostic message is reachable. Use strdup() to copy
+ the token description (grabbing ~30 bytes from the heap) and
+ free that storage later just in case.
+
2024-11-10 G. Branden Robinson <g.branden.robinson@gmail.com>
[troff]: Improve input validation. Use `has_arg()` (inverted if
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index cce80ff03..f592f1e78 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2747,14 +2747,18 @@ static void diagnose_missing_identifier(bool required)
warning(WARN_MISSING, "missing identifier");
}
else if (tok.is_right_brace() || tok.is_tab()) {
- const char *start = tok.description();
+ // token::description() writes to static, class-wide storage, so we
+ // must allocate a copy of it before issuing the next diagnostic.
+ char *start = strdup(tok.description());
do {
tok.next();
} while (tok.is_space() || tok.is_right_brace() || tok.is_tab());
+ // XXX: unreachable code? --GBR
if (!tok.is_newline() && !tok.is_eof())
error("%1 is not allowed before an argument", start);
else if (required)
warning(WARN_MISSING, "missing identifier");
+ free(start);
}
else if (required)
error("expected identifier, got %1", tok.description());
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 23/24: [troff]: Avoid potentially misleading diagnostic.,
G. Branden Robinson <=