From 9be1b8bf083339826cb2475212689da2e582d062 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Mon, 25 Sep 2023 17:28:08 +0200 Subject: [PATCH 1/6] tests: internal: sp: added environment initialization calls Signed-off-by: Leonardo Alminana --- tests/internal/stream_processor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/internal/stream_processor.c b/tests/internal/stream_processor.c index c9e59f50407..0932d0c4480 100644 --- a/tests/internal/stream_processor.c +++ b/tests/internal/stream_processor.c @@ -18,6 +18,7 @@ * limitations under the License. */ +#include #include #include #include @@ -200,6 +201,8 @@ static void invalid_queries() struct flb_sp *sp; struct flb_sp_task *task; + flb_init_env(); + /* Total number of checks for invalid queries */ checks = sizeof(invalid_query_checks) / sizeof(char *); @@ -244,6 +247,8 @@ static void test_select_keys() WSADATA wsa_data; #endif + flb_init_env(); + config = flb_calloc(1, sizeof(struct flb_config)); if (!config) { flb_errno(); @@ -330,6 +335,8 @@ static void test_select_subkeys() WSADATA wsa_data; #endif + flb_init_env(); + config = flb_calloc(1, sizeof(struct flb_config)); if (!config) { flb_errno(); @@ -458,6 +465,8 @@ static void test_window() WSADATA wsa_data; #endif + flb_init_env(); + config = flb_calloc(1, sizeof(struct flb_config)); if (!config) { flb_errno(); @@ -612,6 +621,8 @@ static void test_snapshot() WSADATA wsa_data; #endif + flb_init_env(); + config = flb_calloc(1, sizeof(struct flb_config)); if (!config) { flb_errno(); @@ -773,6 +784,8 @@ static void test_conv_from_str_to_num() #endif out_buf.buffer = NULL; + flb_init_env(); + config = flb_config_init(); config->evl = mk_event_loop_create(256); From 1358c78a03dee93b657d36fbc95880d3cb9e5553 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Tue, 26 Sep 2023 05:57:33 +0100 Subject: [PATCH 2/6] tests: fuzzers: fix fstore div-by-zero Signed-off-by: David Korczynski --- tests/internal/fuzzers/fstore_fuzzer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/internal/fuzzers/fstore_fuzzer.c b/tests/internal/fuzzers/fstore_fuzzer.c index dd7a6cf8b96..92ecf5d7a2d 100644 --- a/tests/internal/fuzzers/fstore_fuzzer.c +++ b/tests/internal/fuzzers/fstore_fuzzer.c @@ -45,6 +45,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) struct flb_fstore_stream *st; struct flb_fstore_file *fsf; + /* Set flb_malloc_mod to be fuzzer-data dependent */ + if (size < 4) { + return 0; + } + flb_malloc_p = 0; + flb_malloc_mod = *(int*)data; + data += 4; + size -= 4; + + /* Avoid division by zero for modulo operations */ + if (flb_malloc_mod == 0) { + flb_malloc_mod = 1; + } + cio_utils_recursive_delete(FSF_STORE_PATH); fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS); st = flb_fstore_stream_create(fs, "abc"); From 0e4ab37587daac6f11552184cba0c3f8b87cc30e Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 25 Sep 2023 16:39:43 -0300 Subject: [PATCH 3/6] filter_log_to_metrics: process the 'add_label' property, which was renamed from 'label'. Signed-off-by: Phillip Whelan --- plugins/filter_log_to_metrics/log_to_metrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/filter_log_to_metrics/log_to_metrics.c b/plugins/filter_log_to_metrics/log_to_metrics.c index cb7f285d882..a61e4827f34 100644 --- a/plugins/filter_log_to_metrics/log_to_metrics.c +++ b/plugins/filter_log_to_metrics/log_to_metrics.c @@ -268,7 +268,7 @@ static int set_labels(struct log_to_metrics_ctx *ctx, snprintf(label_keys[counter], MAX_LABEL_LENGTH - 1, "%s", kv->val); counter++; } - else if (strcasecmp(kv->key, "label") == 0) { + else if (strcasecmp(kv->key, "add_label") == 0) { split = flb_utils_split(kv->val, ' ', 1); if (mk_list_size(split) != 2) { flb_plg_error(ctx->ins, "invalid label, expected name and key"); From eac0bfcea43f6959ff52a196f1af52e0257cd5b3 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 25 Sep 2023 16:40:13 -0300 Subject: [PATCH 4/6] filter_log_to_metrics: fix label test to use 'add_label'. Signed-off-by: Phillip Whelan --- tests/runtime/filter_log_to_metrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/runtime/filter_log_to_metrics.c b/tests/runtime/filter_log_to_metrics.c index b8c8dba1dc2..eb38af61ce4 100644 --- a/tests/runtime/filter_log_to_metrics.c +++ b/tests/runtime/filter_log_to_metrics.c @@ -669,7 +669,7 @@ void flb_test_log_to_metrics_label(void) "metric_name", "test", "metric_description", "Counts messages", "kubernetes_mode", "off", - "label", "pod_name $kubernetes['pod_name']", + "add_label", "pod_name $kubernetes['pod_name']", NULL); out_ffd = flb_output(ctx, (char *) "lib", (void *)&cb_data); From 01764ee656d1e37e9287bbe2760b45c9a2ea6c33 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Tue, 26 Sep 2023 10:15:14 +0200 Subject: [PATCH 5/6] tests: internal: stream_processor: fixed memory leak Signed-off-by: Leonardo Alminana --- tests/internal/stream_processor.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/internal/stream_processor.c b/tests/internal/stream_processor.c index 0932d0c4480..d9886f873f0 100644 --- a/tests/internal/stream_processor.c +++ b/tests/internal/stream_processor.c @@ -526,6 +526,13 @@ static void test_window() usleep(800000); } + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd, task, &out_buf); flb_info("[sp test] id=%i, SQL => '%s'", check->id, check->exec); @@ -569,13 +576,26 @@ static void test_window() /* Hopping event */ if ((t + 1) % check->window_hop_sec == 0) { + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd_hop, task, &out_buf); } /* Window event */ if ((t + 1) % check->window_size_sec == 0 || (t + 1 > check->window_size_sec && (t + 1 - check->window_size_sec) % check->window_hop_sec == 0)) { - flb_free(out_buf.buffer); + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + flb_sp_fd_event_test(task->window.fd, task, &out_buf); } flb_free(data_buf.buffer); From bd64ee6257df50c3b30f7a653f0ac6dfe786d6e2 Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Tue, 26 Sep 2023 10:45:56 +0200 Subject: [PATCH 6/6] tests: internal: stream_processor: fixed memory leak Signed-off-by: Leonardo Alminana --- tests/internal/stream_processor.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/internal/stream_processor.c b/tests/internal/stream_processor.c index d9886f873f0..9afda0bf545 100644 --- a/tests/internal/stream_processor.c +++ b/tests/internal/stream_processor.c @@ -512,6 +512,13 @@ static void test_window() /* We ingest the buffer every second */ for (t = 0; t < check->window_size_sec; t++) { + if (out_buf.buffer != NULL) { + flb_free(out_buf.buffer); + + out_buf.buffer = NULL; + out_buf.size = 0; + } + ret = flb_sp_do_test(sp, task, "samples", strlen("samples"), &data_buf, &out_buf);