summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-09-15 19:14:24 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-09-15 19:14:24 +0100
commit6b546b521ffd02a491708b5919ddeaa1e0f07460 (patch)
treeac3ae01d0a998faec4687540079e1ce5ec838551
parentf9adc3ae2f26154ae38c1f3a39d2814f71f0c1e7 (diff)
Use filename safe strings for all log types.
-rw-r--r--logging.c17
1 files changed, 10 insertions, 7 deletions
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;
}