diff --git a/src/util-profiling-keywords.c b/src/util-profiling-keywords.c index b21eb433e798..fc4092924c00 100644 --- a/src/util-profiling-keywords.c +++ b/src/util-profiling-keywords.c @@ -32,6 +32,7 @@ #include "detect-engine.h" #include "tm-threads.h" #include "util-conf.h" +#include "util-path.h" #include "util-time.h" /** @@ -67,11 +68,13 @@ void SCProfilingKeywordsGlobalInit(void) profiling_keyword_enabled = 1; const char *filename = ConfNodeLookupChildValue(conf, "filename"); if (filename != NULL) { - const char *log_dir; - log_dir = ConfigGetLogDirectory(); - - snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", - log_dir, filename); + if (PathIsAbsolute(filename)) { + strlcpy(profiling_file_name, filename, sizeof(profiling_file_name)); + } else { + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir, + filename); + } const char *v = ConfNodeLookupChildValue(conf, "append"); if (v == NULL || ConfValIsTrue(v)) { diff --git a/src/util-profiling-prefilter.c b/src/util-profiling-prefilter.c index 280d5144e220..2a3aac8dc619 100644 --- a/src/util-profiling-prefilter.c +++ b/src/util-profiling-prefilter.c @@ -30,6 +30,7 @@ #ifdef PROFILING #include "detect-engine-prefilter.h" #include "util-conf.h" +#include "util-path.h" #include "util-time.h" typedef struct SCProfilePrefilterData_ { @@ -67,11 +68,13 @@ void SCProfilingPrefilterGlobalInit(void) profiling_prefilter_enabled = 1; const char *filename = ConfNodeLookupChildValue(conf, "filename"); if (filename != NULL) { - const char *log_dir; - log_dir = ConfigGetLogDirectory(); - - snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", - log_dir, filename); + if (PathIsAbsolute(filename)) { + strlcpy(profiling_file_name, filename, sizeof(profiling_file_name)); + } else { + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir, + filename); + } const char *v = ConfNodeLookupChildValue(conf, "append"); if (v == NULL || ConfValIsTrue(v)) { diff --git a/src/util-profiling-rulegroups.c b/src/util-profiling-rulegroups.c index a6f0a68826a6..b25e89b01bb4 100644 --- a/src/util-profiling-rulegroups.c +++ b/src/util-profiling-rulegroups.c @@ -29,6 +29,7 @@ #ifdef PROFILING #include "util-conf.h" +#include "util-path.h" #include "util-time.h" /** @@ -70,11 +71,13 @@ void SCProfilingSghsGlobalInit(void) profiling_sghs_enabled = 1; const char *filename = ConfNodeLookupChildValue(conf, "filename"); if (filename != NULL) { - const char *log_dir; - log_dir = ConfigGetLogDirectory(); - - snprintf(profiling_file_name, sizeof(profiling_file_name), - "%s/%s", log_dir, filename); + if (PathIsAbsolute(filename)) { + strlcpy(profiling_file_name, filename, sizeof(profiling_file_name)); + } else { + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir, + filename); + } const char *v = ConfNodeLookupChildValue(conf, "append"); if (v == NULL || ConfValIsTrue(v)) { diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index 7a14c93b7731..9984eefd60dd 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -29,6 +29,7 @@ #include "util-byte.h" #include "util-conf.h" +#include "util-path.h" #include "util-time.h" #ifdef PROFILE_RULES @@ -139,12 +140,13 @@ void SCProfilingRulesGlobalInit(void) } const char *filename = ConfNodeLookupChildValue(conf, "filename"); if (filename != NULL) { - - const char *log_dir; - log_dir = ConfigGetLogDirectory(); - - snprintf(profiling_file_name, sizeof(profiling_file_name), - "%s/%s", log_dir, filename); + if (PathIsAbsolute(filename)) { + strlcpy(profiling_file_name, filename, sizeof(profiling_file_name)); + } else { + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_file_name, sizeof(profiling_file_name), "%s/%s", log_dir, + filename); + } const char *v = ConfNodeLookupChildValue(conf, "append"); if (v == NULL || ConfValIsTrue(v)) { diff --git a/src/util-profiling.c b/src/util-profiling.c index 1cf82210726f..6671e40cf578 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -36,6 +36,7 @@ #include "util-byte.h" #include "util-profiling-locks.h" #include "util-conf.h" +#include "util-path.h" #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -172,11 +173,14 @@ SCProfilingInit(void) const char *filename = ConfNodeLookupChildValue(conf, "filename"); if (filename != NULL) { - const char *log_dir; - log_dir = ConfigGetLogDirectory(); - - snprintf(profiling_packets_file_name, sizeof(profiling_packets_file_name), - "%s/%s", log_dir, filename); + if (PathIsAbsolute(filename)) { + strlcpy(profiling_packets_file_name, filename, + sizeof(profiling_packets_file_name)); + } else { + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_packets_file_name, sizeof(profiling_packets_file_name), + "%s/%s", log_dir, filename); + } const char *v = ConfNodeLookupChildValue(conf, "append"); if (v == NULL || ConfValIsTrue(v)) { @@ -196,14 +200,20 @@ SCProfilingInit(void) if (filename == NULL) { filename = "packet_profile.csv"; } + if (PathIsAbsolute(filename)) { + profiling_csv_file_name = SCStrdup(filename); + if (unlikely(profiling_csv_file_name == NULL)) { + FatalError("out of memory"); + } + } else { + profiling_csv_file_name = SCMalloc(PATH_MAX); + if (unlikely(profiling_csv_file_name == NULL)) { + FatalError("out of memory"); + } - const char *log_dir = ConfigGetLogDirectory(); - - profiling_csv_file_name = SCMalloc(PATH_MAX); - if (unlikely(profiling_csv_file_name == NULL)) { - FatalError("out of memory"); + const char *log_dir = ConfigGetLogDirectory(); + snprintf(profiling_csv_file_name, PATH_MAX, "%s/%s", log_dir, filename); } - snprintf(profiling_csv_file_name, PATH_MAX, "%s/%s", log_dir, filename); packet_profile_csv_fp = fopen(profiling_csv_file_name, "w"); if (packet_profile_csv_fp == NULL) {