Skip to content

Commit 7ad8771

Browse files
committed
Merge remote-tracking branch 'upstream/main' into references
2 parents e5a74cb + b96160f commit 7ad8771

File tree

84 files changed

+1944
-1113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1944
-1113
lines changed

csharp/codeql-extractor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ version: 1.22.1
44
column_kind: "utf16"
55
extra_env_vars:
66
DOTNET_GENERATE_ASPNET_CERTIFICATE: "false"
7+
github_api_languages:
8+
- C#
9+
scc_languages:
10+
- C#
711
file_types:
812
- name: cs
913
display_name: C# sources

go/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: extractor ql/lib/go.dbscheme install-deps
1+
all: extractor ql/lib/go.dbscheme
22

33
ifeq ($(OS),Windows_NT)
44
EXE = .exe
@@ -36,9 +36,6 @@ autoformat:
3636
check-formatting:
3737
test -z "$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l)"
3838

39-
install-deps:
40-
bash scripts/install-deps.sh $(CODEQL_LOCK_MODE)
41-
4239
ifeq ($(QHELP_OUT_DIR),)
4340
# If not otherwise specified, compile qhelp to markdown in place
4441
QHELP_OUT_DIR := ql/src
@@ -75,7 +72,7 @@ tools-win64: $(addsuffix .exe,$(addprefix tools/win64/,$(BINARIES)))
7572
$(addsuffix .exe,$(addprefix tools/win64/,$(BINARIES))):
7673
env GOOS=windows GOARCH=amd64 go build -mod=vendor -o $@ ./extractor/cli/$(basename $(@F))
7774

78-
.PHONY: extractor-common extractor extractor-full install-deps
75+
.PHONY: extractor-common extractor extractor-full
7976
extractor-common: codeql-extractor.yml LICENSE ql/lib/go.dbscheme \
8077
tools/tokenizer.jar $(CODEQL_TOOLS)
8178
rm -rf $(EXTRACTOR_PACK_OUT)

go/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ It contains two major components:
99
- static analysis libraries and queries written in [CodeQL](https://codeql.github.com/docs/) that can be
1010
used to analyze such a database to find coding mistakes or security vulnerabilities.
1111

12-
## Installation
13-
14-
Clone this repository.
15-
16-
Run `scripts/install-deps.sh`. This will ensure that the necessary external CodeQL packs are
17-
downloaded to your machine. You will need to re-run this script whenever you pull new commits from
18-
the repo.
19-
20-
If you want to use the CodeQL extension for Visual Studio Code, import this repository into your VS
21-
Code workspace.
22-
2312
## Usage
2413

2514
To analyze a Go codebase, either use the [CodeQL command-line

go/codeql-extractor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pull_request_triggers:
66
- "**/glide.yaml"
77
- "**/Gopkg.toml"
88
column_kind: "utf8"
9+
github_api_languages:
10+
- Go
11+
scc_languages:
12+
- Go
913
file_types:
1014
- name: go
1115
display_name: Go
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The predicate `getNumParameter` on `FuncTypeExpr` has been changed to actually give the number of parameters. It previously gave the number of parameter declarations. `getNumParameterDecl` has been introduced to preserve this functionality.

go/ql/lib/semmle/go/AST.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,27 @@ class DeclParent extends @declparent, AstNode {
194194
}
195195

196196
/**
197-
* An AST node whose children include fields.
197+
* An AST node whose children include field declarations.
198+
*
199+
* A field declaration can be in a struct, a function (for parameter or result
200+
* variables), or an interface (in which case it is a method or embedding spec).
198201
*/
199202
class FieldParent extends @fieldparent, AstNode {
200203
/**
201-
* Gets the `i`th field of this node.
204+
* Gets the `i`th field declaration of this node.
202205
*
203-
* Note that the precise indices of fields are considered an implementation detail
204-
* and are subject to change without notice.
206+
* Note that the precise indices of field declarations are considered an
207+
* implementation detail and are subject to change without notice.
205208
*/
206209
FieldBase getField(int i) { fields(result, this, i) }
207210

208211
/**
209-
* Gets a child field of this node in the AST.
212+
* Gets a child field declaration of this node in the AST.
210213
*/
211214
FieldBase getAField() { result = this.getField(_) }
212215

213216
/**
214-
* Gets the number of child fields of this node.
217+
* Gets the number of child field declarations of this node.
215218
*/
216219
int getNumFields() { result = count(this.getAField()) }
217220
}

go/ql/lib/semmle/go/Decls.qll

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,35 @@ class AliasSpec extends @aliasspec, TypeSpec { }
416416
class TypeDefSpec extends @typedefspec, TypeSpec { }
417417

418418
/**
419-
* A field declaration, of a struct, a function (in which case this is a parameter or result variable),
420-
* or an interface (in which case this is a method or embedding spec).
419+
* A field declaration, in a struct, a function (for parameter or result
420+
* variables), or an interface (in which case this is a method or embedding
421+
* spec).
422+
*
423+
* Examples:
424+
*
425+
* ```go
426+
* Name string `json:"name"`
427+
* s string
428+
* x, y int
429+
* p *Point
430+
* Close() error
431+
* io.Reader
432+
* ~int | float32
433+
* ```
434+
* as in the following code:
435+
* ```go
436+
* struct {
437+
* io.Reader
438+
* Name string `json:"name"`
439+
* x, y int
440+
* }
441+
* func (p *Point) f(s string) (x, y int) { }
442+
* type MyInterface interface {
443+
* Close() error
444+
* io.Reader
445+
* ~int32 | float32
446+
* }
447+
* ```
421448
*/
422449
class FieldBase extends @field, ExprParent {
423450
/**
@@ -433,6 +460,22 @@ class FieldBase extends @field, ExprParent {
433460

434461
/**
435462
* A field declaration in a struct type.
463+
*
464+
* Examples:
465+
*
466+
* ```go
467+
* Name string `json:"name"`
468+
* x, y int
469+
* ```
470+
*
471+
* as in the following code:
472+
*
473+
* ```go
474+
* struct {
475+
* Name string `json:"name"`
476+
* x, y int
477+
* }
478+
* ```
436479
*/
437480
class FieldDecl extends FieldBase, Documentable, ExprParent {
438481
StructTypeExpr st;
@@ -464,6 +507,20 @@ class FieldDecl extends FieldBase, Documentable, ExprParent {
464507

465508
/**
466509
* An embedded field declaration in a struct.
510+
*
511+
* Examples:
512+
*
513+
* ```go
514+
* io.Reader
515+
* ```
516+
*
517+
* as in the following code:
518+
*
519+
* ```go
520+
* struct {
521+
* io.Reader
522+
* }
523+
* ```
467524
*/
468525
class EmbeddedFieldDecl extends FieldDecl {
469526
EmbeddedFieldDecl() { not exists(this.getNameExpr(_)) }
@@ -473,6 +530,20 @@ class EmbeddedFieldDecl extends FieldDecl {
473530

474531
/**
475532
* A function parameter or result variable declaration.
533+
*
534+
* Examples:
535+
*
536+
* ```go
537+
* s string
538+
* x, y int
539+
* ```
540+
*
541+
* as in the following code:
542+
*
543+
* ```go
544+
* func f(s string, x, y int) { }
545+
* func g() (s string, x, y int){ return }
546+
* ```
476547
*/
477548
class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
478549
int rawIndex;
@@ -507,6 +578,19 @@ class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
507578

508579
/**
509580
* A parameter declaration.
581+
*
582+
* Examples:
583+
*
584+
* ```go
585+
* s string
586+
* x, y int
587+
* ```
588+
*
589+
* as in the following code:
590+
*
591+
* ```go
592+
* func f(s string, x, y int) { }
593+
* ```
510594
*/
511595
class ParameterDecl extends ParameterOrResultDecl {
512596
ParameterDecl() { rawIndex >= 0 }
@@ -524,6 +608,20 @@ class ParameterDecl extends ParameterOrResultDecl {
524608

525609
/**
526610
* A receiver declaration in a function declaration.
611+
*
612+
* Examples:
613+
*
614+
* ```go
615+
* p *Point
616+
* r io.Reader
617+
* ```
618+
*
619+
* as in the following code:
620+
*
621+
* ```go
622+
* func (p *Point) f() { }
623+
* func (r io.Reader) g() { }
624+
* ```
527625
*/
528626
class ReceiverDecl extends FieldBase, Documentable, ExprParent {
529627
FuncDecl fd;
@@ -547,6 +645,22 @@ class ReceiverDecl extends FieldBase, Documentable, ExprParent {
547645

548646
/**
549647
* A result variable declaration.
648+
*
649+
* Examples:
650+
*
651+
* ```go
652+
* error
653+
* r io.Reader
654+
* x, y int
655+
* ```
656+
*
657+
* as in the following code:
658+
*
659+
* ```go
660+
* func f(error) { return nil }
661+
* func g(r io.Reader) { return nil }
662+
* func h(x, y int) { return }
663+
* ```
550664
*/
551665
class ResultVariableDecl extends ParameterOrResultDecl {
552666
ResultVariableDecl() { rawIndex < 0 }
@@ -564,6 +678,22 @@ class ResultVariableDecl extends ParameterOrResultDecl {
564678

565679
/**
566680
* A type parameter declaration in a type specification.
681+
*
682+
* Examples:
683+
*
684+
* ```go
685+
* S, T comparable
686+
* U any
687+
* K ~int32 | float32
688+
* _ any
689+
* ```
690+
*
691+
* as in the following code:
692+
*
693+
* ```go
694+
* type GenericStruct[S, T comparable, U any, K ~int32 | float32, _ any] struct { }
695+
* func GenericFunction[S, T comparable, U any, K ~int32 | float32, _ any]() {}
696+
* ```
567697
*/
568698
class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
569699
TypeParamDecl() { typeparamdecls(this, _, _) }
@@ -615,6 +745,24 @@ class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
615745

616746
/**
617747
* A method or embedding specification in an interface type expression.
748+
*
749+
* Examples:
750+
*
751+
* ```go
752+
* Close() error
753+
* io.Reader
754+
* ~int32 | float32
755+
* ```
756+
*
757+
* as in the following code:
758+
*
759+
* ```go
760+
* type MyInterface interface {
761+
* Close() error
762+
* io.Reader
763+
* ~int32 | float32
764+
* }
765+
* ```
618766
*/
619767
class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
620768
InterfaceTypeExpr ite;
@@ -636,6 +784,20 @@ class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
636784

637785
/**
638786
* A method specification in an interface.
787+
*
788+
* Examples:
789+
*
790+
* ```go
791+
* Close() error
792+
* ```
793+
*
794+
* as in the following code:
795+
*
796+
* ```go
797+
* type MyInterface interface {
798+
* Close() error
799+
* }
800+
* ```
639801
*/
640802
class MethodSpec extends InterfaceMemberSpec {
641803
Expr name;
@@ -654,6 +816,22 @@ class MethodSpec extends InterfaceMemberSpec {
654816

655817
/**
656818
* An embedding specification in an interface.
819+
*
820+
* Examples:
821+
*
822+
* ```go
823+
* io.Reader
824+
* ~int32 | float32
825+
* ```
826+
*
827+
* as in the following code:
828+
*
829+
* ```go
830+
* type MyInterface interface {
831+
* io.Reader
832+
* ~int32 | float32
833+
* }
834+
* ```
657835
*/
658836
class EmbeddingSpec extends InterfaceMemberSpec {
659837
EmbeddingSpec() { not exists(this.getChildExpr(1)) }

0 commit comments

Comments
 (0)