From 731ab10110c78a3614debf1318cc723659d99dc0 Mon Sep 17 00:00:00 2001 From: Thien-Thi Nguyen Date: Thu, 27 Jan 2022 16:31:05 -0500 Subject: 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. --- src/ChangeLog | 11 +++++++++++ src/rlog.c | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index b6c904e..3d649a9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2022-01-27 Thien-Thi Nguyen + + 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 [int] Move USED_IF_HAVE_MADVISE to beginning of param decl 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); -- cgit v1.2.3-70-g09d2