Skip to content

Conversation

@matriv
Copy link
Contributor

@matriv matriv commented Mar 14, 2020

Fix NPE when null is passed as a parameter for a parameterized
pattern of LIKE/RLIKE. e.g.: field LIKE ? params=[null]`
Check for null pattern in LIKE/RLIKE as for RLIKE (RegexpQuery) we
get an IllegalArgumentExpression from Lucence but for LIKE
(WildcardQuery) we get an NPE.

Fixes: #53557

Fix NPE when `null` is passed as a parameter for a parameterized
pattern of LIKE/RLIKE. e.g.: `field LIKE ?` params=[null]`
Check for null pattern in LIKE/RLIKE as for RLIKE (RegexpQuery) we
get an IllegalArgumentExpression from Lucence but for LIKE
(WildcardQuery) we get an NPE.

Fixes: elastic#53557
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/SQL)

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice quick fix

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

String pattern = string(ctx.value);
if (pattern == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the pattern always has to be non-null, I think it would be better to report the error at the parser level instead of letting it propagate all the way to the tree which would be invalid anyway...
Just like w do with pos below by throwing a ParsingException

Copy link
Contributor Author

@matriv matriv Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it and I kind of liked more the separation of Parsing to an illegalarg case.
In my mind null is acceptable in parsing but not for the evaluation of the expression.
But if you prefer the ParsingException I can also do.

@astefan what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where possible, the arguments should be checked as soon as possible - the whole method checks the validity of the pattern right after parsing - checking its existence is one that was missed.
I see no advantages of postponing the check.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But +1 to @costin's comment here. And I would like to see an IT, as well. Thanks.

@matriv
Copy link
Contributor Author

matriv commented Mar 16, 2020

@astefan isn't an IT a bit too much for this null check?

@matriv matriv merged commit ec3481e into elastic:master Mar 16, 2020
@matriv matriv deleted the fix-53557 branch March 16, 2020 12:49
matriv added a commit that referenced this pull request Mar 16, 2020
Fix NPE when `null` is passed as a parameter for a parameterized
pattern of LIKE/RLIKE. e.g.: `field LIKE ?` params=[null]`
Check for null pattern in LIKE/RLIKE as for RLIKE (RegexpQuery) we
get an IllegalArgumentExpression from Lucence but for LIKE
(WildcardQuery) we get an NPE.

Fixes: #53557
(cherry picked from commit ec3481e)
matriv added a commit that referenced this pull request Mar 16, 2020
Fix NPE when `null` is passed as a parameter for a parameterized
pattern of LIKE/RLIKE. e.g.: `field LIKE ?` params=[null]`
Check for null pattern in LIKE/RLIKE as for RLIKE (RegexpQuery) we
get an IllegalArgumentExpression from Lucence but for LIKE
(WildcardQuery) we get an NPE.

Fixes: #53557
(cherry picked from commit ec3481e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL: NPE for a null parameter in LIKE

6 participants