Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle malformed regex comparisons during parsing (fixes #3301) #3351

Conversation

rnubel
Copy link
Contributor

@rnubel rnubel commented Jul 16, 2015

Previously, if your query used a regex operator but didn't follow it with a regex, parseRegex would return an empty RegexLiteral, and the expression parser would put that into the right-hand side of the expression. This caused a nil-pointer panic when the query was later executed. This change adds a check at the parsing level and returns an error message if a regex operator (e.g. =~) is not followed by an actual regex.

Before, doing the following would cause a panic and kill the server:

> SELECT * FROM cpu WHERE value = 0 AND region =~ 'adf' LIMIT 2;
ERR: Get http://localhost:8086/query?db=mydb&q=SELECT+%2A+FROM+cpu+WHERE+value+%3D+0+AND+region+%3D~+%27adf%27+LIMIT+2%3B: EOF

After, we gracefully handle the problem during the parsing stage:

> SELECT * FROM cpu WHERE value = 0 AND region =~ 'adf' LIMIT 2;
ERR: error parsing query: found adf, expected regex at line 1, char 48
  • CHANGELOG.md updated
  • Rebased/mergable
  • Tests pass
  • Sign CLA (if not already signed)

@dgnorton
Copy link
Contributor

+1 after CHANGELOG.md update. Thanks, @rnubel !

Previously, parseRegex could return an empty RegexLiteral
and the expression parser would put that into the right-hand
side of the expression, causing a nil-pointer panic when
the query was later executed. This change adds a check at
the parsing level and returns an error message if a regex
operator (e.g. =~) is not followed by an actual regex.
@rnubel rnubel force-pushed the fix/parser/require_regex_after_regex_operator branch from ffa918a to 1ade199 Compare July 16, 2015 23:14
@rnubel rnubel changed the title Require a regex after a regex operator when parsing (fixes #3301) Handle malformed regex comparisons during parsing (fixes #3301) Jul 16, 2015
@rnubel
Copy link
Contributor Author

rnubel commented Jul 17, 2015

@dgnorton: Changelog update added. I think this is all set.

@otoolep
Copy link
Contributor

otoolep commented Jul 17, 2015

Rebased here: #3365

@otoolep otoolep closed this Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants