BUG/MINOR: halog: exit with error when some output filters are set simultaneosly
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 16 Jul 2025 12:35:28 +0000 (14:35 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 26 Aug 2025 06:38:58 +0000 (08:38 +0200)
Exit with an error if multiple output filters (-ic, -srv, -st, -tc, -u*, etc.)
are used at the same time.

halog is designed to process and display output for only one filter at a time.
Using multiple filters simultaneously can cause a crash because the program is
not designed to manage multiple, separate result sets (e.g., one for
IP counts, another for URLs).

Supporting simultaneous filters would require a redesign to collect entries for
each filter in separate ebtree. This would negatively impact performance and is
not requested for the moment. This patch prevents the crash by checking filter
combinations just after the command line parsing.

This issue was reported in GitHUB #3031.
This should be backported in all stable versions.

(cherry picked from commit 254e4d59f75784c237e0c51596c6e0ca8730e717)
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
(cherry picked from commit dd276c752d5edfe26778ded9006dea40d5e33d23)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

admin/halog/halog.c

index 884a606..3d89411 100644 (file)
@@ -123,6 +123,22 @@ struct url_stat {
 #define FILT2_PRESERVE_QUERY    0x02
 #define FILT2_EXTRACT_CAPTURE   0x04
 
+#define FILT_OUTPUT_FMT   (FILT_COUNT_ONLY| \
+                          FILT_COUNT_STATUS| \
+                          FILT_COUNT_SRV_STATUS| \
+                          FILT_COUNT_COOK_CODES| \
+                          FILT_COUNT_TERM_CODES| \
+                          FILT_COUNT_URL_ONLY| \
+                          FILT_COUNT_URL_COUNT| \
+                          FILT_COUNT_URL_ERR| \
+                          FILT_COUNT_URL_TAVG| \
+                          FILT_COUNT_URL_TTOT| \
+                          FILT_COUNT_URL_TAVGO| \
+                          FILT_COUNT_URL_TTOTO| \
+                          FILT_COUNT_URL_BAVG| \
+                          FILT_COUNT_URL_BTOT| \
+                          FILT_COUNT_IP_COUNT)
+
 unsigned int filter = 0;
 unsigned int filter2 = 0;
 unsigned int filter_invert = 0;
@@ -192,7 +208,7 @@ void help()
               "                         you can also use -n to start from earlier then field %d\n"
               " -query                  preserve the query string for per-URL (-u*) statistics\n"
               "\n"
-              "Output format - only one may be used at a time\n"
+              "Output format - **only one** may be used at a time\n"
               " -c    only report the number of lines that would have been printed\n"
               " -pct  output connect and response times percentiles\n"
               " -st   output number of requests per HTTP status code\n"
@@ -898,6 +914,9 @@ int main(int argc, char **argv)
        if (!filter && !filter2)
                die("No action specified.\n");
 
+       if ((filter & FILT_OUTPUT_FMT) & ((filter & FILT_OUTPUT_FMT) - 1))
+               die("Please, set only one output filter.\n");
+
        if (filter & FILT_ACC_COUNT && !filter_acc_count)
                filter_acc_count=1;