summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThien-Thi Nguyen <ttn@gnu.org>2022-01-27 16:31:05 -0500
committerThien-Thi Nguyen <ttn@gnu.org>2022-01-27 16:31:05 -0500
commit731ab10110c78a3614debf1318cc723659d99dc0 (patch)
tree3edc7bf26d4dfc66bb55896da4dd032f20d6d4d0
parentdbfb9b77012e33708bf0d025dd0e01f9915d9c31 (diff)
downloadrcs-731ab10110c78a3614debf1318cc723659d99dc0.tar.gz
rlog: Handle unexpected byte in edit script
Reported by Ray Bellis: https://mail.gnu.org/r/bug-rcs/2022-01/msg00000.html * src/rlog.c (count_a_d): If the edit script stanza does not start w/ the expected 'a' or 'd' dispatch, display error message with diagnostic and abort.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/rlog.c22
2 files changed, 32 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b6c904e..3d649a9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
2022-01-27 Thien-Thi Nguyen <ttn@gnu.org>
+ rlog: Handle unexpected byte in edit script
+
+ Reported by Ray Bellis:
+ https://mail.gnu.org/r/bug-rcs/2022-01/msg00000.html
+
+ * rlog.c (count_a_d): If the edit script stanza
+ does not start w/ the expected 'a' or 'd' dispatch,
+ display error message with diagnostic and abort.
+
+2022-01-27 Thien-Thi Nguyen <ttn@gnu.org>
+
[int] Move USED_IF_HAVE_MADVISE to beginning of param decl
* b-fro.c (fro_trundling): ...here, for arg ‘sequential’.
diff --git a/src/rlog.c b/src/rlog.c
index 404ec86..2b4de4b 100644
--- a/src/rlog.c
+++ b/src/rlog.c
@@ -127,9 +127,29 @@ count_a_d (long *a, long *d, struct atat *edits)
for (char const *p = s.string; p < end; p++)
{
- bool add = ('a' == *p++);
+ bool add = ('a' == *p);
long count;
+ /* Sanity check. */
+ if (! add && 'd' != *p)
+ {
+ long adjust = 0;
+ char const *before = s.string;
+ size_t remaining = p - before;
+
+ while (remaining && (before = memchr (before, '\n', remaining)))
+ {
+ before++;
+ adjust++;
+ remaining = p - before;
+ }
+ complain ("\n");
+ fatal_syntax (adjust + edits->lno,
+ "unexpected byte in edit script: 0x%02x",
+ *p);
+ }
+ p++;
+
/* Skip the line number. */
p = strchr (p, ' ');
count = read_positive_integer (&p);