From 6b546b521ffd02a491708b5919ddeaa1e0f07460 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 15 Sep 2019 19:14:24 +0100 Subject: Use filename safe strings for all log types. --- logging.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'logging.c') diff --git a/logging.c b/logging.c index 6935673..db3fbfb 100644 --- a/logging.c +++ b/logging.c @@ -99,16 +99,19 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { } } - // Make "filename safe" copies of from and to names to ensure filename ends up being safe - char from[MAXCHAR], to[MAXCHAR]; + // Make "filename safe" copies of from and to names, as well as ircdstate->ircdname + // to ensure filename ends up being safe + char from[MAXCHAR], to[MAXCHAR], ircdname[MAXCHAR]; strcpy(from, tokens[0]); strcpy(to, tokens[2]); + strcpy(ircdname, ircdstate->ircdname); // Remove unsafe characters (assuming POSIX, just strip "/" and replace with "_") replacechar(from, '/', '_'); replacechar(to, '/', '_'); + replacechar(ircdname, '/', '_'); // Ensure filename wouldn't be too long (+ 4 for ".log") - if (strlen(from) + 4 > NAME_MAX || strlen(to) + 4 > NAME_MAX) { - debugprint(DEBUG_CRIT, "Filename would be too long if logging either '%s' or '%s', returning!\n", from, to); + if (strlen(from) + 4 > NAME_MAX || strlen(to) + 4 > NAME_MAX || strlen(ircdname) + 4 > NAME_MAX ) { + debugprint(DEBUG_CRIT, "Filename would be too long if logging either '%s', '%s' or '%s', returning!\n", from, to, ircdname); return 0; } @@ -224,7 +227,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { return 0; } - if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, ircdstate->ircdname)) { + if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, ircdname)) { debugprint(DEBUG_CRIT, "Error while preparing log filename for network, returning!\n"); return 0; } @@ -260,7 +263,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { snprintf(line, MAXCHAR, "%s (%s) has quit (%s)", tokens[1] + 1, tokens[1] + posbang + 1, str); // Build the log filename - if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[0])) { + if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, from)) { debugprint(DEBUG_CRIT, "logline(): Error while preparing log filename for quit, returning!\n"); return 0; } @@ -277,7 +280,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) { snprintf(line, MAXCHAR, "%s is now known as %s", tokens[1], str); // Build the log filename - if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[0])) { + if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, from)) { debugprint(DEBUG_CRIT, "logline(): Error while preparing log filename for nick, returning!\n"); return 0; } -- cgit v1.2.3