diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-07-10 22:16:24 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-07-10 22:16:24 +0100 |
commit | e413787a5dbf0b4e377935d2192bc00cf9830cb8 (patch) | |
tree | ffaded1f46ce8ea3ecbe98f7704fca5dcfee294a /replay.c | |
parent | cdc97d3e55cf029dbdd91dfa213700af9714a41a (diff) |
Ensure string isn't too long when writing to replay log.
Diffstat (limited to 'replay.c')
-rw-r--r-- | replay.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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]; |