Skip to content

Commit f210c66

Browse files
stokscedsiper
authored andcommitted
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 <[email protected]>
1 parent 307ea1d commit f210c66

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/flb_config.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
742742
{
743743
int ret;
744744
char *tmp;
745-
char *name;
745+
char *name = NULL;
746746
char *s_type;
747747
struct mk_list *list;
748748
struct mk_list *head;
@@ -752,7 +752,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
752752
struct flb_cf_section *s;
753753
struct flb_cf_group *processors = NULL;
754754
int i;
755-
void *ins;
755+
void *ins = NULL;
756756

757757
if (type == FLB_CF_CUSTOM) {
758758
s_type = "custom";
@@ -771,7 +771,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
771771
list = &cf->outputs;
772772
}
773773
else {
774-
return -1;
774+
goto error;
775775
}
776776

777777
mk_list_foreach(head, list) {
@@ -780,7 +780,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
780780
if (!name) {
781781
flb_error("[config] section '%s' is missing the 'name' property",
782782
s_type);
783-
return -1;
783+
goto error;
784784
}
785785

786786
/* translate the variable */
@@ -806,10 +806,8 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
806806
if (!ins) {
807807
flb_error("[config] section '%s' tried to instance a plugin name "
808808
"that doesn't exist", name);
809-
flb_sds_destroy(name);
810-
return -1;
809+
goto error;
811810
}
812-
flb_sds_destroy(name);
813811

814812
/*
815813
* iterate section properties and populate instance by using specific
@@ -871,6 +869,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
871869
flb_error("[config] could not configure property '%s' on "
872870
"%s plugin with section name '%s'",
873871
kv->key, s_type, name);
872+
goto error;
874873
}
875874
}
876875

@@ -880,22 +879,44 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
880879
if (type == FLB_CF_INPUT) {
881880
ret = flb_processors_load_from_config_format_group(((struct flb_input_instance *) ins)->processor, processors);
882881
if (ret == -1) {
883-
return -1;
882+
goto error;
884883
}
885884
}
886885
else if (type == FLB_CF_OUTPUT) {
887886
ret = flb_processors_load_from_config_format_group(((struct flb_output_instance *) ins)->processor, processors);
888887
if (ret == -1) {
889-
return -1;
888+
goto error;
890889
}
891890
}
892891
else {
893892
flb_error("[config] section '%s' does not support processors", s_type);
894893
}
895894
}
895+
896+
flb_sds_destroy(name);
896897
}
897898

898899
return 0;
900+
901+
error:
902+
if (name != NULL) {
903+
flb_sds_destroy(name);
904+
}
905+
if (ins != NULL) {
906+
if (type == FLB_CF_CUSTOM) {
907+
flb_custom_instance_destroy(ins);
908+
}
909+
else if (type == FLB_CF_INPUT) {
910+
flb_input_instance_destroy(ins);
911+
}
912+
else if (type == FLB_CF_FILTER) {
913+
flb_filter_instance_destroy(ins);
914+
}
915+
else if (type == FLB_CF_OUTPUT) {
916+
flb_output_instance_destroy(ins);
917+
}
918+
}
919+
return -1;
899920
}
900921
/* Load a struct flb_config_format context into a flb_config instance */
901922
int flb_config_load_config_format(struct flb_config *config, struct flb_cf *cf)

0 commit comments

Comments
 (0)