From 25d457b274ad2168a8b23ed2c9b1ab760111578f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 9 May 2017 17:47:32 +0100 Subject: [PATCH 1/2] Fix race condition in the matcher code We have a static list of matchers, one for each kind, but newMatcher() was writing to those on every filter creation. Remove writes, set the attribute on matcher init instead. --- filters/matcher.go | 1 - filters/registry.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/filters/matcher.go b/filters/matcher.go index 8013fcaa3..202c15a73 100644 --- a/filters/matcher.go +++ b/filters/matcher.go @@ -123,7 +123,6 @@ func (matcher *negativeRegexMatcher) Compare(valA, valB interface{}) bool { func newMatcher(matchType string) (matcherT, error) { if m, found := matcherConfig[matchType]; found { - m.setOperator(matchType) return m, nil } e := fmt.Sprintf("%s not matched with any know match type", matchType) diff --git a/filters/registry.go b/filters/registry.go index 88073ceca..8f706015d 100644 --- a/filters/registry.go +++ b/filters/registry.go @@ -21,12 +21,12 @@ var matcherRegex = "[=!<>~]+" var filterRegex = "^(@)?[a-zA-Z_][a-zA-Z0-9_]*" var matcherConfig = map[string]matcherT{ - equalOperator: &equalMatcher{}, - notEqualOperator: ¬EqualMatcher{}, - moreThanOperator: &moreThanMatcher{}, - lessThanOperator: &lessThanMatcher{}, - regexpOperator: ®expMatcher{}, - negativeRegexOperator: &negativeRegexMatcher{}, + equalOperator: &equalMatcher{abstractMatcher{Operator: equalOperator}}, + notEqualOperator: ¬EqualMatcher{abstractMatcher{Operator: notEqualOperator}}, + moreThanOperator: &moreThanMatcher{abstractMatcher{Operator: moreThanOperator}}, + lessThanOperator: &lessThanMatcher{abstractMatcher{Operator: lessThanOperator}}, + regexpOperator: ®expMatcher{abstractMatcher{Operator: regexpOperator}}, + negativeRegexOperator: &negativeRegexMatcher{abstractMatcher{Operator: negativeRegexOperator}}, } type filterConfig struct { From 37304d615a4d4770bd1826b7a9efd30e4dbf6556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 9 May 2017 17:49:24 +0100 Subject: [PATCH 2/2] Remove unused code setOperator is no longer used, remove it as it's dangerous and useless --- filters/matcher.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/filters/matcher.go b/filters/matcher.go index 202c15a73..8b0a82a1c 100644 --- a/filters/matcher.go +++ b/filters/matcher.go @@ -23,10 +23,6 @@ type abstractMatcher struct { Operator string } -func (matcher *abstractMatcher) setOperator(operator string) { - matcher.Operator = operator -} - func (matcher *abstractMatcher) GetOperator() string { return matcher.Operator }