From 040b166eb221ca68501992febe1bf59f1d3582d8 Mon Sep 17 00:00:00 2001 From: Sauyon Lee Date: Tue, 17 Aug 2021 11:22:36 -0700 Subject: [PATCH] Add new style build constraints and add test for the old style --- .../go/controlflow/ControlFlowGraph/linux.go | 1 + .../controlflow/ControlFlowGraph/nonlinux.go | 1 + .../StdlibTaintFlow/Syscall_non_win.go | 1 + .../CompareIdenticalValues/constants.go | 3 +- .../RedundantCode/ExprHasNoEffect/tst.go | 1 + .../ExprHasNoEffect/tst_nonlinux.go | 1 + .../Test32BitArchitectureBuildConstraints.go | 1 + .../Test64BitArchitectureBuildConstraints.go | 1 + .../TestNoArchitectureBuildConstraints.go | 4 +-- .../CWE-681/TestOldBuildConstraints.go | 29 +++++++++++++++++++ 10 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 ql/test/query-tests/Security/CWE-681/TestOldBuildConstraints.go diff --git a/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/linux.go b/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/linux.go index 66c40b54084..4f8f6b615fe 100644 --- a/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/linux.go +++ b/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package main diff --git a/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/nonlinux.go b/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/nonlinux.go index 3347a26fa7a..e0ec489338f 100644 --- a/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/nonlinux.go +++ b/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/nonlinux.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package main diff --git a/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Syscall_non_win.go b/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Syscall_non_win.go index c2d7f55e259..06db4fa3c0b 100644 --- a/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Syscall_non_win.go +++ b/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Syscall_non_win.go @@ -1,5 +1,6 @@ // Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT. +//go:build !windows // +build !windows package main diff --git a/ql/test/query-tests/RedundantCode/CompareIdenticalValues/constants.go b/ql/test/query-tests/RedundantCode/CompareIdenticalValues/constants.go index d999a815ecf..50ec41c081c 100644 --- a/ql/test/query-tests/RedundantCode/CompareIdenticalValues/constants.go +++ b/ql/test/query-tests/RedundantCode/CompareIdenticalValues/constants.go @@ -1,4 +1,5 @@ -// +build linux, amd64 +//go:build (linux && ignore) || amd64 +// +build linux,ignore amd64 package main diff --git a/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst.go b/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst.go index a81e4c931b0..485ee15fe8c 100644 --- a/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst.go +++ b/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package main diff --git a/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst_nonlinux.go b/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst_nonlinux.go index 43bd1a07ad6..2326c147a9a 100644 --- a/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst_nonlinux.go +++ b/ql/test/query-tests/RedundantCode/ExprHasNoEffect/tst_nonlinux.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package main diff --git a/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraints.go b/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraints.go index 11e317d46cd..2914e2178e9 100644 --- a/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraints.go +++ b/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraints.go @@ -1,3 +1,4 @@ +//go:build (386 || amd64p32 || arm || armbe || mips || mipsle || mips64p32 || mips64p32le || ppc || s390 || sparc) && gc && go1.4 // +build 386 amd64p32 arm armbe mips mipsle mips64p32 mips64p32le ppc s390 sparc // +build gc // +build go1.4 diff --git a/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraints.go b/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraints.go index 82bd2965cee..8c1e23fe721 100644 --- a/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraints.go +++ b/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraints.go @@ -1,3 +1,4 @@ +//go:build (amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || s390x || sparc64) && gc && go1.4 // +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 // +build gc // +build go1.4 diff --git a/ql/test/query-tests/Security/CWE-681/TestNoArchitectureBuildConstraints.go b/ql/test/query-tests/Security/CWE-681/TestNoArchitectureBuildConstraints.go index 98cb6abdd61..905ee836b9b 100644 --- a/ql/test/query-tests/Security/CWE-681/TestNoArchitectureBuildConstraints.go +++ b/ql/test/query-tests/Security/CWE-681/TestNoArchitectureBuildConstraints.go @@ -1,5 +1,5 @@ -// +build gc -// +build go1.4 +//go:build gc && go1.4 +// +build gc,go1.4 package main diff --git a/ql/test/query-tests/Security/CWE-681/TestOldBuildConstraints.go b/ql/test/query-tests/Security/CWE-681/TestOldBuildConstraints.go new file mode 100644 index 00000000000..e7f6b058ed7 --- /dev/null +++ b/ql/test/query-tests/Security/CWE-681/TestOldBuildConstraints.go @@ -0,0 +1,29 @@ +// autoformat-ignore (gofmt adds new style build constraints) +// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 +// +build gc +// +build go1.4 + +package main + +import ( + "strconv" +) + +func oldTestIntSink64() { + { + parsed, err := strconv.ParseInt("3456", 10, 64) + if err != nil { + panic(err) + } + _ = int(parsed) // OK + _ = uint(parsed) // OK + } + { + parsed, err := strconv.ParseUint("3456", 10, 64) + if err != nil { + panic(err) + } + _ = int(parsed) // OK + _ = uint(parsed) // OK + } +}