]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
profiling: allow absolute paths 11642/head
authorVictor Julien <vjulien@oisf.net>
Wed, 10 Jul 2024 09:29:35 +0000 (11:29 +0200)
committerJeff Lucovsky <jlucovsky@oisf.net>
Sun, 18 Aug 2024 14:00:55 +0000 (10:00 -0400)
Ticket #6490.

(cherry picked from commit 855cc8963612387ff0440b707ce3145523f1a9ac)

src/util-profiling-keywords.c
src/util-profiling-prefilter.c
src/util-profiling-rulegroups.c
src/util-profiling-rules.c
src/util-profiling.c

index b21eb433e7985455b86dd8454340d875bc3a7880..fc4092924c000a058674b447d531899671377e06 100644 (file)
@@ -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)) {
index 280d5144e220c6f0abcf58337d89f32ecbeb556d..2a3aac8dc61984e9dc9499d201bb67df841d363a 100644 (file)
@@ -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)) {
index a6f0a68826a6d6bb7dccf76e707949749f9587b2..b25e89b01bb46b7d58e9ffbcc875ea4cf87afca9 100644 (file)
@@ -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)) {
index 7a14c93b7731e9c1354edf0a0fe2547128913f96..9984eefd60dda29b49552ca67a3dcd5e0610107f 100644 (file)
@@ -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)) {
index 1cf82210726f6880067c0b4ee3e567ed935d1761..6671e40cf578458e9740b7b116b13220e5de93e8 100644 (file)
@@ -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) {