From e413787a5dbf0b4e377935d2192bc00cf9830cb8 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Wed, 10 Jul 2019 22:16:24 +0100 Subject: Ensure string isn't too long when writing to replay log. --- replay.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/replay.c b/replay.c index 3a40e16..f4635c1 100644 --- a/replay.c +++ b/replay.c @@ -343,6 +343,17 @@ int lastspokesecondsago(char *nick, char *basedir) { // With the ":foo!bar@baz "prefix being important. // Returns 1 on success or 0 on failure. int writereplayline(char *str, char *basedir) { + // Ensure "str" isn't too long + if (strlen(str) >= MAXCHAR) { + // String is too long! + debugprint(DEBUG_CRIT, "writereplayline(): str '%s' was too long (%d out of a max of %d characters).\n", str, strlen(str), MAXCHAR - 1); + return 0; + } else if (strlen(str) >= MAXCHAR - 2 && str[strlen(str) - 1] != '\r' && str[strlen(str)] != '\n') { + // Ensure string can fit CRLF at the end if it doesn't already have it + debugprint(DEBUG_CRIT, "writereplayline(): non-CRLF message too long to append CRLF to.\n"); + return 0; + } + FILE *fp; char line[MAXCHAR]; char filename[PATH_MAX]; -- cgit v1.2.3