summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-07-10 22:16:24 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-07-10 22:16:24 +0100
commite413787a5dbf0b4e377935d2192bc00cf9830cb8 (patch)
treeffaded1f46ce8ea3ecbe98f7704fca5dcfee294a
parentcdc97d3e55cf029dbdd91dfa213700af9714a41a (diff)
Ensure string isn't too long when writing to replay log.
-rw-r--r--replay.c11
1 files changed, 11 insertions, 0 deletions
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];