Skip to content

Commit 915d567

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 <[email protected]>
1 parent de8670a commit 915d567

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
@@ -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 */
@@ -778,10 +778,8 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
778778
if (!ins) {
779779
flb_error("[config] section '%s' tried to instance a plugin name "
780780
"that doesn't exist", name);
781-
flb_sds_destroy(name);
782-
return -1;
781+
goto error;
783782
}
784-
flb_sds_destroy(name);
785783

786784
/*
787785
* iterate section properties and populate instance by using specific
@@ -843,6 +841,7 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
843841
flb_error("[config] could not configure property '%s' on "
844842
"%s plugin with section name '%s'",
845843
kv->key, s_type, name);
844+
goto error;
846845
}
847846
}
848847

@@ -852,22 +851,44 @@ static int configure_plugins_type(struct flb_config *config, struct flb_cf *cf,
852851
if (type == FLB_CF_INPUT) {
853852
ret = flb_processors_load_from_config_format_group(((struct flb_input_instance *) ins)->processor, processors);
854853
if (ret == -1) {
855-
return -1;
854+
goto error;
856855
}
857856
}
858857
else if (type == FLB_CF_OUTPUT) {
859858
ret = flb_processors_load_from_config_format_group(((struct flb_output_instance *) ins)->processor, processors);
860859
if (ret == -1) {
861-
return -1;
860+
goto error;
862861
}
863862
}
864863
else {
865864
flb_error("[config] section '%s' does not support processors", s_type);
866865
}
867866
}
867+
868+
flb_sds_destroy(name);
868869
}
869870

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

0 commit comments

Comments
 (0)