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

Detect sources produced by non-CommaOk TypeAssert of a Pointer type. #190

Closed
mlevesquedion opened this issue Nov 13, 2020 · 0 comments · Fixed by #217
Closed

Detect sources produced by non-CommaOk TypeAssert of a Pointer type. #190

mlevesquedion opened this issue Nov 13, 2020 · 0 comments · Fixed by #217
Assignees

Comments

@mlevesquedion
Copy link
Contributor

Consider this test case:

func TestSourcePointerAssertedFromParameterEface(e interface{}) {
	s := e.(*core.Source)
	core.Sink(s) // TODO want "a source has reached a sink"
}

The SSA is:

func TestSourcePointerAssertedFromParameterEface(e interface{})
0: entry
	0(*ssa.TypeAssert     ): t0 = typeassert e.(*example.com/core.Source)
	1(*ssa.Alloc          ): t1 = new [1]interface{} (varargs)
	2(*ssa.IndexAddr      ): t2 = &t1[0:int]
	3(*ssa.MakeInterface  ): t3 = make interface{} <- *example.com/core.Source (t0)
	4(*ssa.Store          ): *t2 = t3
	5(*ssa.Slice          ): t4 = slice t1[:]
	6(*ssa.Call           ): t5 = example.com/core.Sink(t4...)
	7(*ssa.Return         ): return

It it were a CommaOk TypeAssert, there would be an Extract, so the Source would be detected in sources.go:sourcesFromBlocks.
If it were a TypeAssert to a Source value (not a pointer), there would be an Alloc, so again the source would be detected in sources.go:sourcesFromBlocks.

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 a pull request may close this issue.

2 participants