From 5603b857a9182ea3129dce023b4ee5eed31a5f4e Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Thu, 14 Mar 2019 14:16:29 -0700 Subject: [PATCH] Check if label value is valid when unmarhsaling external labels from YAML, add a test to config_tests for valid/invalid external label value. Signed-off-by: Callum Styan --- config/config.go | 3 +++ config/config_test.go | 3 +++ config/testdata/labelvalue.bad.yml | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 config/testdata/labelvalue.bad.yml diff --git a/config/config.go b/config/config.go index e3594e052..b3b33094d 100644 --- a/config/config.go +++ b/config/config.go @@ -304,6 +304,9 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if !model.LabelName(l.Name).IsValid() { return fmt.Errorf("%q is not a valid label name", l.Name) } + if !model.LabelValue(l.Value).IsValid() { + return fmt.Errorf("%q is not a valid label value", l.Value) + } } // First set the correct scrape interval, then check that the timeout diff --git a/config/config_test.go b/config/config_test.go index 78422c69b..9d35e9e53 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -714,6 +714,9 @@ var expectedErrors = []struct { }, { filename: "labelname2.bad.yml", errMsg: `"not:allowed" is not a valid label name`, + }, { + filename: "labelvalue.bad.yml", + errMsg: `"\xff" is not a valid label value`, }, { filename: "regex.bad.yml", errMsg: "error parsing regexp", diff --git a/config/testdata/labelvalue.bad.yml b/config/testdata/labelvalue.bad.yml new file mode 100644 index 000000000..7873eb174 --- /dev/null +++ b/config/testdata/labelvalue.bad.yml @@ -0,0 +1,3 @@ +global: + external_labels: + name: !!binary "/w==" \ No newline at end of file