File tree Expand file tree Collapse file tree 4 files changed +14
-10
lines changed
test/library-tests/semmle/go/frameworks Expand file tree Collapse file tree 4 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ module Afero {
9292 predicate aferoSanitizer ( DataFlow:: Node n ) {
9393 exists ( Function f |
9494 f .hasQualifiedName ( aferoPackage ( ) , [ "NewBasePathFs" , "NewIOFS" ] ) and
95- DataFlow :: localFlow ( f .getACall ( ) , n )
95+ TaintTracking :: localTaint ( f .getACall ( ) , n )
9696 )
9797 }
9898
@@ -103,10 +103,12 @@ module Afero {
103103 *
104104 * e.g.`n2 := &afero.Afero{Fs: afero.NewBasePathFs(osFS, "./")}` n1 is `afero.NewBasePathFs(osFS, "./")`
105105 */
106- predicate additionalTaintStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
107- exists ( StructLit st | st .getType ( ) .hasQualifiedName ( aferoPackage ( ) , "Afero" ) |
108- n1 .asExpr ( ) = st .getAnElement ( ) .( KeyValueExpr ) .getAChildExpr ( ) and
109- n2 .asExpr ( ) = st
110- )
106+ class AdditionalTaintStep extends TaintTracking:: AdditionalTaintStep {
107+ override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
108+ exists ( StructLit st | st .getType ( ) .hasQualifiedName ( aferoPackage ( ) , "Afero" ) |
109+ n1 .asExpr ( ) = st .getAnElement ( ) .( KeyValueExpr ) .getAChildExpr ( ) and
110+ n2 .asExpr ( ) = st
111+ )
112+ }
111113 }
112114}
Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ module FileSystemAccessTest implements TestSig {
1313 tag = "FileSystemAccess"
1414 )
1515 or
16- exists ( DataFlow:: Node succ , DataFlow:: Node pred | Afero:: additionalTaintStep ( pred , succ ) |
16+ exists ( DataFlow:: Node succ , DataFlow:: Node pred |
17+ any ( Afero:: AdditionalTaintStep adts ) .step ( pred , succ )
18+ |
1719 succ .hasLocationInfo ( location .getFile ( ) .getAbsolutePath ( ) , location .getStartLine ( ) ,
1820 location .getStartColumn ( ) , location .getEndLine ( ) , location .getEndColumn ( ) ) and
1921 element = succ .toString ( ) and
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ package main
44
55import (
66 "fmt"
7- "github.com/spf13/afero"
87 "net/http"
98 "os"
109 "regexp"
10+
11+ "github.com/spf13/afero"
1112)
1213
1314func main () {
@@ -63,8 +64,7 @@ func Afero(writer http.ResponseWriter, request *http.Request) {
6364 fmt .Println ("Afero:" )
6465 newBasePathFs := afero .NewBasePathFs (osFS , "tmp" )
6566 basePathFs0 := & afero.Afero {Fs : newBasePathFs } // $ succ=Afero pred=newBasePathFs
66- // following is a FP, and in a dataflow configuration if we use Afero::additionalTaintStep then we won't have following in results
67- fmt .Println (basePathFs0 .ReadFile (filepath )) // $ SPURIOUS: FileSystemAccess=filepath
67+ fmt .Println (basePathFs0 .ReadFile (filepath ))
6868
6969 // IOFS ==> OK
7070 fmt .Println ("IOFS:" )
You can’t perform that action at this time.
0 commit comments