File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
lib/semmle/go/dataflow/internal
test/library-tests/semmle/go/frameworks/TaintSteps Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -408,3 +408,19 @@ class ListOfConstantsComparisonSanitizerGuard extends TaintTracking::DefaultTain
408408 this = DataFlow:: BarrierGuard< listOfConstantsComparisonSanitizerGuard / 3 > :: getABarrierNode ( )
409409 }
410410}
411+
412+ /**
413+ * The `clear` built-in function deletes or zeroes out all elements of a map or slice
414+ * and therefore acts as a general sanitizer for taint flow to any uses dominated by it.
415+ */
416+ private class ClearSanitizer extends DefaultTaintSanitizer {
417+ ClearSanitizer ( ) {
418+ exists ( SsaWithFields var , DataFlow:: CallNode call , DataFlow:: Node arg | this = var .getAUse ( ) |
419+ call = Builtin:: clear ( ) .getACall ( ) and
420+ arg = call .getAnArgument ( ) and
421+ arg = var .getAUse ( ) and
422+ arg != this and
423+ this .getBasicBlock ( ) .( ReachableBasicBlock ) .dominates ( this .getBasicBlock ( ) )
424+ )
425+ }
426+ }
Original file line number Diff line number Diff line change 509509| main.go | main.go:28:2:28:4 | implicit dereference | main.go:28:2:28:9 | selection of Body |
510510| main.go | main.go:28:2:28:4 | req | main.go:28:2:28:4 | implicit dereference |
511511| main.go | main.go:28:2:28:9 | selection of Body | main.go:27:2:27:2 | definition of b |
512+ | main.go | main.go:34:2:34:4 | implicit dereference | main.go:32:16:32:18 | definition of req |
513+ | main.go | main.go:34:2:34:4 | implicit dereference | main.go:34:2:34:9 | selection of Body |
514+ | main.go | main.go:34:2:34:4 | req | main.go:34:2:34:4 | implicit dereference |
515+ | main.go | main.go:34:2:34:9 | selection of Body | main.go:33:2:33:2 | definition of b |
512516| math/big.Accuracy.String | file://:0:0:0:0 | [summary param] -1 in String | file://:0:0:0:0 | [summary] to write: ReturnValue in String |
513517| math/big.Float.MarshalText | file://:0:0:0:0 | [summary param] -1 in MarshalText | file://:0:0:0:0 | [summary] to write: ReturnValue in MarshalText |
514518| math/big.Float.String | file://:0:0:0:0 | [summary param] -1 in String | file://:0:0:0:0 | [summary] to write: ReturnValue in String |
Original file line number Diff line number Diff line change @@ -28,3 +28,10 @@ func readTest(req *http.Request) string {
2828 req .Body .Read (b )
2929 return string (b )
3030}
31+
32+ func clearTest (req * http.Request ) string {
33+ b := make ([]byte , 8 )
34+ req .Body .Read (b )
35+ clear (b ) // should prevent taint flow
36+ return string (b )
37+ }
You can’t perform that action at this time.
0 commit comments