From 8a4a5c2aa21308ca9ce34cfbe38f663c9ace8c13 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 4 Jun 2018 12:34:16 +0000 Subject: [PATCH] Log only the filename, not the full path in LOGGER. Fixes #900. --- auto_tests/helpers.h | 4 +--- toxcore/logger.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h index bebde35b75..b953e29aa8 100644 --- a/auto_tests/helpers.h +++ b/auto_tests/helpers.h @@ -43,7 +43,7 @@ static const char *tox_log_level_name(TOX_LOG_LEVEL level) return ""; } -static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint32_t line, const char *func, +static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) { if (level == TOX_LOG_LEVEL_TRACE) { @@ -51,8 +51,6 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3 } uint32_t index = user_data ? *(uint32_t *)user_data : 0; - const char *file = strrchr(path, '/'); - file = file ? file + 1 : path; fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); } diff --git a/toxcore/logger.c b/toxcore/logger.c index ff34f994ea..edde806f83 100644 --- a/toxcore/logger.c +++ b/toxcore/logger.c @@ -31,6 +31,7 @@ #include #include #include +#include struct Logger { @@ -111,7 +112,19 @@ void logger_write(const Logger *log, LOGGER_LEVEL level, const char *file, int l return; } - /* Format message */ + // Only pass the file name, not the entire file path, for privacy reasons. + // The full path may contain PII of the person compiling toxcore (their + // username and directory layout). + const char *filename = strrchr(file, '/'); + file = filename ? filename + 1 : file; +#if defined(_WIN32) || defined(__CYGWIN__) + // On Windows, the path separator *may* be a backslash, so we look for that + // one too. + const char *windows_filename = strrchr(file, '\\'); + file = windows_filename ? windows_filename + 1 : file; +#endif + + // Format message char msg[1024]; va_list args; va_start(args, format);