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

ruleguard: consider || operator support in Where cond #26

Closed
quasilyte opened this issue Dec 25, 2019 · 5 comments · Fixed by #142
Closed

ruleguard: consider || operator support in Where cond #26

quasilyte opened this issue Dec 25, 2019 · 5 comments · Fixed by #142
Assignees
Labels
DSL May require DSL changes

Comments

@quasilyte
Copy link
Owner

quasilyte commented Dec 25, 2019

Needed for context-keys-type checker implementation.

m.Match(`context.WithValue($_, $k, $_)`).
	Where(m["k"].Type.Is("bool") ||
		m["k"].Type.Is("int") ||
		m["k"].Type.Is("int8") ||
		m["k"].Type.Is("int16") ||
		m["k"].Type.Is("int32") ||
		m["k"].Type.Is("int64") ||
		m["k"].Type.Is("uint") ||
		m["k"].Type.Is("uint8") ||
		m["k"].Type.Is("uint16") ||
		m["k"].Type.Is("uint32") ||
		m["k"].Type.Is("uint64") ||
		m["k"].Type.Is("uintptr") ||
		m["k"].Type.Is("float32") ||
		m["k"].Type.Is("float64") ||
		m["k"].Type.Is("complex64") ||
		m["k"].Type.Is("complex128") ||
		m["k"].Type.Is("string")).
	Report(`should not use basic type as key in context.WithValue`)

Or maybe we need to add "basic" type predicate for now.

@quasilyte quasilyte changed the title ruleguard/typematch: consider || operator support ruleguard: consider || operator support in Where cond Dec 25, 2019
@quasilyte quasilyte added the DSL May require DSL changes label Jan 10, 2020
@lamg
Copy link
Contributor

lamg commented Aug 31, 2020

Also makes sense to add support for the rest of boolean operators.

@quasilyte
Copy link
Owner Author

I think it's not hard to add new operators, but it's better to have some usage examples before we implement them. :)

@lamg
Copy link
Contributor

lamg commented Aug 31, 2020

Actually I think the only one I really miss is ||. I thought && wasn't fully supported because a parenthesized expression with it inside wasn't recognized.

@quasilyte
Copy link
Owner Author

Could you show your || example?

In my original example, the code would be better with Type.IsBasic() which will be faster (no need to apply N conditions).

@dgryski
Copy link
Contributor

dgryski commented Sep 1, 2020

I know I have rules in my semgrep-go/ruleguard.rules.go file that could be considerably cleaned up using ||

@quasilyte quasilyte self-assigned this Oct 31, 2020
quasilyte added a commit that referenced this issue Dec 20, 2020
Refactored Where() filter parsing code.

Implemented || operator while at it.

Fixes #115 !(A && B) conditions now work properly
Fixes #26  A || B    conditions are now implemented
quasilyte added a commit that referenced this issue Dec 20, 2020
Refactored Where() filter parsing code.

Implemented || operator while at it.

Fixes #115 !(A && B) conditions now work properly
Fixes #26  A || B    conditions are now implemented
quasilyte added a commit that referenced this issue Dec 20, 2020
Refactored Where() filter parsing code.

Implemented || operator while at it.

Fixes #115 !(A && B) conditions now work properly
Fixes #26  A || B    conditions are now implemented
quasilyte added a commit that referenced this issue Dec 20, 2020
Refactored Where() filter parsing code.

Implemented || operator while at it.

Fixes #115 !(A && B) conditions now work properly
Fixes #26  A || B    conditions are now implemented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DSL May require DSL changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants