Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Fix field lookup in cyclic structs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Schaefer committed Jun 19, 2020
1 parent 7c2358c commit 2df8c27
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions change-notes/2020-06-19-cyclic-field-lookup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lgtm,codescanning
* A bug has been fixed that could cause the analysis not to terminate in the presence of cycles through embedded struct fields.
1 change: 1 addition & 0 deletions ql/src/semmle/go/Types.qll
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class StructType extends @structtype, CompositeType {
) {
hasOwnField(_, name, tp, isEmbedded) and depth = 0 and isMethod = false
or
not hasOwnField(_, name, _, _) and
exists(Type embedded | hasEmbeddedField(embedded, depth - 1) |
embedded.getUnderlyingType().(StructType).hasOwnField(_, name, tp, isEmbedded) and
isMethod = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| cyclic.go:4:3:4:3 | s | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types |
| pkg1/embedding.go:19:23:19:26 | base | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
| pkg1/embedding.go:22:27:22:30 | base | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
| pkg1/embedding.go:25:24:25:31 | embedder | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s | s |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder | base |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder2 | base |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder3 | base |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| cyclic.go:4:3:4:3 | s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types | s | s |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder | base |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder2 | base |
| pkg1/embedding.go:19:23:19:26 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder3 | base |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
| embedder3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder3 |
| embedder4 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder4 |
| ptrembedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.ptrembedder |
| s | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.s |
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
| embedder4 | pkg1/embedding.go:35:16:38:1 | struct type | base | base |
| embedder4 | pkg1/embedding.go:35:16:38:1 | struct type | f | int |
| ptrembedder | pkg1/embedding.go:22:18:22:32 | struct type | base | * base |
| s | cyclic.go:3:8:5:1 | struct type | s | * s |
1 change: 1 addition & 0 deletions ql/test/library-tests/semmle/go/Types/Types.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
| embedder3 | embedder3 |
| embedder4 | embedder4 |
| ptrembedder | ptrembedder |
| s | s |
5 changes: 5 additions & 0 deletions ql/test/library-tests/semmle/go/Types/cyclic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

type s struct {
*s
}

0 comments on commit 2df8c27

Please sign in to comment.