Skip to content

Commit 4ccdcf9

Browse files
committed
config: error configure_plugins_type on invalid properties
After this change, when a plugin configuration contains an invalid property, `configure_plugins_type` returns an error which ultimately crashes fluentbit, instead of only printing an error log and continuing on. The change also fixes a small issue where `name` was printed by `flb_error` after it was freed. To properly test this change and get the test to pass with `-DSANITIZE_ADDRESS=On` on all platforms, I had to update `configure_plugins_type` to free objects that it fails to instantiate. Signed-off-by: Bradley Laney <bradley.laney@chronosphere.io>
1 parent 332d6b6 commit 4ccdcf9

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

src/flb_config.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
714714
{
715715
int ret;
716716
char *tmp;
717-
char *name;
717+
char *name = NULL;
718718
char *s_type;
719719
struct mk_list *list;
720720
struct mk_list *head;
@@ -724,7 +724,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
724724
struct flb_cf_section *s;
725725
struct flb_cf_group *processors = NULL;
726726
int i;
727-
void *ins;
727+
void *ins = NULL;
728728

729729
if (type == FLB_CF_CUSTOM) {
730730
s_type = "custom";
@@ -743,7 +743,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
743743
list = &cf->outputs;
744744
}
745745
else {
746-
return -1;
746+
goto error;
747747
}
748748

749749
mk_list_foreach(head, list) {
@@ -752,7 +752,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
752752
if (!name) {
753753
flb_error("[config] section '%s' is missing the 'name' property",
754754
s_type);
755-
return -1;
755+
goto error;
756756
}
757757

758758
/* translate the variable */
@@ -779,9 +779,8 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
779779
flb_error("[config] section '%s' tried to instance a plugin name "
780780
"that doesn't exist", name);
781781
flb_sds_destroy(name);
782-
return -1;
782+
goto error;
783783
}
784-
flb_sds_destroy(name);
785784

786785
/*
787786
* iterate section properties and populate instance by using specific
@@ -843,6 +842,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
843842
flb_error("[config] could not configure property '%s' on "
844843
"%s plugin with section name '%s'",
845844
kv->key, s_type, name);
845+
goto error;
846846
}
847847
}
848848

@@ -852,22 +852,44 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
852852
if (type == FLB_CF_INPUT) {
853853
ret = flb_processors_load_from_config_format_group(((struct flb_input_instance *) ins)->processor, processors);
854854
if (ret == -1) {
855-
return -1;
855+
goto error;
856856
}
857857
}
858858
else if (type == FLB_CF_OUTPUT) {
859859
ret = flb_processors_load_from_config_format_group(((struct flb_output_instance *) ins)->processor, processors);
860860
if (ret == -1) {
861-
return -1;
861+
goto error;
862862
}
863863
}
864864
else {
865865
flb_error("[config] section '%s' does not support processors", s_type);
866866
}
867867
}
868+
869+
flb_sds_destroy(name);
868870
}
869871

870872
return 0;
873+
874+
error:
875+
if (name != NULL) {
876+
flb_sds_destroy(name);
877+
}
878+
if (ins != NULL) {
879+
if (type == FLB_CF_CUSTOM) {
880+
flb_custom_instance_destroy(ins);
881+
}
882+
else if (type == FLB_CF_INPUT) {
883+
flb_input_instance_destroy(ins);
884+
}
885+
else if (type == FLB_CF_FILTER) {
886+
flb_filter_instance_destroy(ins);
887+
}
888+
else if (type == FLB_CF_OUTPUT) {
889+
flb_output_instance_destroy(ins);
890+
}
891+
}
892+
return -1;
871893
}
872894
/* Load a struct flb_config_format context into a flb_config instance */
873895
int flb_config_load_config_format(struct flb_config *config, struct flb_cf *cf)

tests/internal/config_format_yaml.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22

33
#include <fluent-bit/flb_info.h>
4+
#include <fluent-bit/flb_input.h>
5+
#include <fluent-bit/flb_output.h>
46
#include <fluent-bit/flb_mem.h>
57
#include <fluent-bit/flb_kv.h>
68
#include <fluent-bit/flb_str.h>
@@ -833,6 +835,34 @@ static void test_upstream_servers()
833835
flb_cf_destroy(cf);
834836
}
835837

838+
static void test_invalid_property()
839+
{
840+
char* test_cases[] = {
841+
FLB_TESTS_CONF_PATH "/invalid_input_property.yaml",
842+
FLB_TESTS_CONF_PATH "/invalid_output_property.yaml",
843+
NULL,
844+
};
845+
846+
struct flb_cf *cf;
847+
struct flb_config *config;
848+
int ret;
849+
int i;
850+
851+
for (i = 0; test_cases[i] != NULL; i++) {
852+
cf = flb_cf_yaml_create(NULL, test_cases[i], NULL, 0);
853+
TEST_ASSERT(cf != NULL);
854+
855+
config = flb_config_init();
856+
TEST_ASSERT(config != NULL);
857+
858+
ret = flb_config_load_config_format(config, cf);
859+
TEST_ASSERT_(ret == -1, "expected invalid property to return an error in file %s", test_cases[i]);
860+
861+
flb_config_exit(config);
862+
flb_cf_destroy(cf);
863+
}
864+
}
865+
836866
TEST_LIST = {
837867
{ "basic" , test_basic},
838868
{ "customs section", test_customs_section},
@@ -846,5 +876,6 @@ TEST_LIST = {
846876
{ "stream_processor", test_stream_processor},
847877
{ "plugins", test_plugins},
848878
{ "upstream_servers", test_upstream_servers},
879+
{ "invalid_input_property", test_invalid_property},
849880
{ 0 }
850881
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pipeline:
2+
inputs:
3+
- name: dummy
4+
log_level: thisdoesnotexist
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pipeline:
2+
outputs:
3+
- name: stdout
4+
match: '*'
5+
log_level: thisdoesnotexist

0 commit comments

Comments
 (0)