Skip to content

Commit e72a3fd

Browse files
committed
lib/logstorage: properly parse unquoted regexp filters ending with *
Use getCompoundToken() instead of getCompoundFuncArg() for obtaining regexp filter value, since getCompoundFuncArg() skips trailing '*' chars. This allows detecting invalid queries in the https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8582 .
1 parent 7413000 commit e72a3fd

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/victorialogs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta
4949
* BUGFIX: [query API](https://docs.victoriametrics.com/victorialogs/querying/#querying-logs): properly set storage node authorization in cluster mode when [Basic Auth](https://docs.victoriametrics.com/victorialogs/cluster/#security) is enabled. See [#9080](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9080).
5050
* BUGFIX: [Journald data ingestion](https://docs.victoriametrics.com/victorialogs/data-ingestion/journald/): properly read log timestamp from `__REALTIME_TIMESTAMP` field according to [the docs](https://docs.victoriametrics.com/victorialogs/data-ingestion/journald/#time-field). See [#9144](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9144). The bug has been introduced in [v1.22.0-victorialogs](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.22.0-victorialogs).
5151
* BUGFIX: [data ingestion](https://docs.victoriametrics.com/victorialogs/data-ingestion/): support `-` as a timestamp value, as described in [RFC5424](https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.3).
52+
* BUGFIX: [LogsQL regexp filter](https://docs.victoriametrics.com/victorialogs/logsql/#regexp-filter): properly parse unquoted filter ending with `*`, such as `foo:~bar.*`. It must be parsed as `foo:~"bar.*"`, while previously it was incorrectly parsed as `foo:~"bar."`.
5253

5354
## [v1.23.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.23.3-victorialogs)
5455

lib/logstorage/parser.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ func newFilterRegexp(fieldName, arg string) (filter, error) {
20142014

20152015
re, err := regexutil.NewRegex(arg)
20162016
if err != nil {
2017-
return nil, fmt.Errorf("invalid regexp %q: %w", arg, err)
2017+
return nil, fmt.Errorf("invalid regexp %q:%q: %w", getCanonicalColumnName(fieldName), arg, err)
20182018
}
20192019
fr := &filterRegexp{
20202020
fieldName: getCanonicalColumnName(fieldName),
@@ -2025,7 +2025,10 @@ func newFilterRegexp(fieldName, arg string) (filter, error) {
20252025

20262026
func parseFilterTilda(lex *lexer, fieldName string) (filter, error) {
20272027
lex.nextToken()
2028-
arg := getCompoundFuncArg(lex)
2028+
arg, err := getCompoundToken(lex)
2029+
if err != nil {
2030+
return nil, fmt.Errorf("cannot read regexp for field %q: %w", getCanonicalColumnName(fieldName), err)
2031+
}
20292032
return newFilterRegexp(fieldName, arg)
20302033
}
20312034

lib/logstorage/parser_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func TestLexer(t *testing.T) {
6464
[]string{"{", "foo", "=", "bar", ",", "a", "=~", "baz", ",", "b", "!=", "cd", ",", "d,}a", "!~", "abc", "}", "def"})
6565
f(`_stream:{foo="bar",a=~"baz", b != 'cd',"d,}a"!~abc}`,
6666
[]string{"_stream", ":", "{", "foo", "=", "bar", ",", "a", "=~", "baz", ",", "b", "!=", "cd", ",", "d,}a", "!~", "abc", "}"})
67+
68+
f(`foo:~*`, []string{"foo", ":", "~", "*"})
6769
}
6870

6971
func TestQuery_AddTimeFilter(t *testing.T) {
@@ -1325,6 +1327,10 @@ func TestParseQuery_Success(t *testing.T) {
13251327
f(`foo bar:~".*"`, `foo`)
13261328
f(`foo bar:~""`, `foo`)
13271329
f(`foo bar:~".+"`, `foo bar:*`)
1330+
f(`x:~.*`, `*`)
1331+
f(`~.*`, `*`)
1332+
f(`x:~a*`, `x:~"a*"`)
1333+
f(`~a*`, `~"a*"`)
13281334

13291335
// seq filter
13301336
f(`seq()`, `seq()`)
@@ -2022,6 +2028,8 @@ func TestParseQuery_Failure(t *testing.T) {
20222028
f("foo:re(bar")
20232029
f("re(`ab(`)")
20242030
f(`re(a b)`)
2031+
f(`foo:~*`)
2032+
f(`~*`)
20252033

20262034
// invalid seq
20272035
f(`seq(`)

0 commit comments

Comments
 (0)