From 0460b2e9f7d8d2b16f227212b0243b6cf3ee11c2 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 16 Jun 2020 00:35:55 +0200 Subject: [PATCH] fix: stop path leakage in logger --- CMakeLists.txt | 5 ++--- include/logger.h | 18 ++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44b53b2..9e2d682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,9 @@ project(core) add_executable(core main.c) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -luuid -lsqlite3 -g -fprofile-arcs -ftest-coverage") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra -luuid -lsqlite3 -ffile-prefix-map=${CMAKE_SOURCE_DIR}/=/") -string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE) -add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") add_definitions("-DMG_ENABLE_EXTRA_ERRORS_DESC") diff --git a/include/logger.h b/include/logger.h index 10a2553..37efc33 100644 --- a/include/logger.h +++ b/include/logger.h @@ -7,20 +7,14 @@ #include #include -#ifndef SOURCE_PATH_SIZE - #define SOURCE_PATH_SIZE 0 -#endif - -#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE) - void logger_log(FILE *stream, log_level_t level, const char *filename, int line, const char *func, const char *msg, ...); -#define LOG_TRACE(...) logger_log(stdout, LOG_LEVEL_TRACE, __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) -#define LOG_DEBUG(...) logger_log(stdout, LOG_LEVEL_DEBUG, __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) -#define LOG_INFO(...) logger_log(stdout, LOG_LEVEL_INFO , __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) -#define LOG_WARN(...) logger_log(stdout, LOG_LEVEL_WARN , __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) -#define LOG_ERROR(...) logger_log(stderr, LOG_LEVEL_ERROR, __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) -#define LOG_FATAL(...) logger_log(stderr, LOG_LEVEL_FATAL, __FILENAME__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_TRACE(...) logger_log(stdout, LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_DEBUG(...) logger_log(stdout, LOG_LEVEL_DEBUG, __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_INFO(...) logger_log(stdout, LOG_LEVEL_INFO , __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_WARN(...) logger_log(stdout, LOG_LEVEL_WARN , __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_ERROR(...) logger_log(stderr, LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#define LOG_FATAL(...) logger_log(stderr, LOG_LEVEL_FATAL, __FILE__, __LINE__, __func__, ##__VA_ARGS__) #endif //CORE_LOGGER_H