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

Commit 0dd7676

Browse files
author
Max Schaefer
committed
Add another function-model test.
1 parent 1c5dd51 commit 0dd7676

6 files changed

Lines changed: 30 additions & 1 deletion

File tree

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| parameter 0 | main.go:53:2:53:22 | call to op2 | main.go:53:6:53:8 | "-" |
33
| parameter 0 | main.go:55:2:55:27 | call to Printf | main.go:55:13:55:20 | "%d, %d" |
44
| parameter 0 | main.go:57:2:57:27 | call to Printf | main.go:57:13:57:20 | "%d, %d" |
5+
| parameter 0 | reset.go:12:2:12:21 | call to Reset | reset.go:12:15:12:20 | source |
56
| parameter 0 | tst.go:10:2:10:29 | call to ReadFrom | tst.go:10:23:10:28 | reader |
67
| parameter 1 | main.go:51:2:51:14 | call to op | main.go:51:10:51:10 | 1 |
78
| parameter 1 | main.go:53:2:53:22 | call to op2 | main.go:53:11:53:11 | 2 |
@@ -12,5 +13,6 @@
1213
| parameter 2 | main.go:55:2:55:27 | call to Printf | main.go:55:26:55:26 | y |
1314
| parameter 2 | main.go:57:2:57:27 | call to Printf | main.go:57:26:57:26 | y |
1415
| receiver | main.go:53:14:53:21 | call to bump | main.go:53:14:53:14 | c |
16+
| receiver | reset.go:12:2:12:21 | call to Reset | reset.go:12:2:12:7 | reader |
1517
| receiver | tst.go:10:2:10:29 | call to ReadFrom | tst.go:10:2:10:12 | bytesBuffer |
1618
| result | tst.go:9:17:9:33 | call to new | tst.go:9:2:9:12 | definition of bytesBuffer |

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getExitNode.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| parameter 0 | main.go:5:1:11:1 | function declaration | main.go:5:9:5:10 | definition of op |
22
| parameter 0 | main.go:13:1:20:1 | function declaration | main.go:13:10:13:11 | definition of op |
33
| parameter 0 | main.go:40:1:48:1 | function declaration | main.go:40:12:40:12 | definition of b |
4+
| parameter 0 | reset.go:8:1:16:1 | function declaration | reset.go:8:27:8:27 | definition of r |
45
| parameter 0 | tst.go:8:1:11:1 | function declaration | tst.go:8:12:8:17 | definition of reader |
56
| parameter 1 | main.go:5:1:11:1 | function declaration | main.go:5:20:5:20 | definition of x |
67
| parameter 1 | main.go:13:1:20:1 | function declaration | main.go:13:21:13:21 | definition of x |

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionModelStep.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import go
22

33
class BytesReadFrom extends TaintTracking::FunctionModel, Method {
4-
BytesReadFrom() { this.(Method).hasQualifiedName("bytes", "Buffer", "ReadFrom") }
4+
BytesReadFrom() { this.hasQualifiedName("bytes", "Buffer", "ReadFrom") }
5+
6+
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
7+
inp.isParameter(0) and outp.isReceiver()
8+
}
9+
}
10+
11+
class ReaderReset extends TaintTracking::FunctionModel, Method {
12+
ReaderReset() { this.hasQualifiedName("bufio", "Reader", "Reset") }
513

614
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
715
inp.isParameter(0) and outp.isReceiver()

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_getEntryNode.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| result | main.go:13:1:20:1 | function declaration | main.go:15:9:15:13 | ...+... |
55
| result | main.go:13:1:20:1 | function declaration | main.go:17:10:17:14 | ...-... |
66
| result | main.go:26:1:29:1 | function declaration | main.go:28:9:28:15 | selection of count |
7+
| result | reset.go:8:1:16:1 | function declaration | reset.go:15:9:15:12 | sink |
78
| result 0 | main.go:31:1:33:1 | function declaration | main.go:32:9:32:10 | 23 |
89
| result 0 | main.go:35:1:38:1 | function declaration | main.go:35:15:35:15 | zero value for x |
910
| result 0 | main.go:35:1:38:1 | function declaration | main.go:36:13:36:14 | 23 |

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_getExitNode.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| parameter 0 | reset.go:12:2:12:21 | call to Reset | reset.go:9:2:9:7 | definition of source |
12
| parameter 0 | tst.go:10:2:10:29 | call to ReadFrom | tst.go:8:12:8:17 | definition of reader |
23
| receiver | tst.go:10:2:10:29 | call to ReadFrom | tst.go:9:2:9:12 | definition of bytesBuffer |
34
| result | main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"io"
6+
)
7+
8+
func bufioReaderResetTest(r io.Reader) bufio.Reader {
9+
source := r
10+
11+
var reader bufio.Reader
12+
reader.Reset(source)
13+
sink := reader
14+
15+
return sink
16+
}

0 commit comments

Comments
 (0)