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

Commit 19348d2

Browse files
committed
Simplify tests
1 parent 1591ed3 commit 19348d2

File tree

4 files changed

+123
-426
lines changed

4 files changed

+123
-426
lines changed

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/ArchiveTar.go

Lines changed: 45 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -9,202 +9,97 @@ import (
99
)
1010

1111
func TaintStepTest_ArchiveTarFileInfoHeader_B0I0O0(sourceCQL interface{}) interface{} {
12-
// The flow is from `fromFileInfo291` into `intoHeader926`.
13-
14-
// Assume that `sourceCQL` has the underlying type of `fromFileInfo291`:
15-
fromFileInfo291 := sourceCQL.(os.FileInfo)
16-
17-
// Call the function that transfers the taint
18-
// from the parameter `fromFileInfo291` to result `intoHeader926`
19-
// (`intoHeader926` is now tainted).
20-
intoHeader926, _ := tar.FileInfoHeader(fromFileInfo291, "")
21-
22-
// Return the tainted `intoHeader926`:
23-
return intoHeader926
12+
fromFileInfo656 := sourceCQL.(os.FileInfo)
13+
intoHeader414, _ := tar.FileInfoHeader(fromFileInfo656, "")
14+
return intoHeader414
2415
}
2516

2617
func TaintStepTest_ArchiveTarNewReader_B0I0O0(sourceCQL interface{}) interface{} {
27-
// The flow is from `fromReader527` into `intoReader503`.
28-
29-
// Assume that `sourceCQL` has the underlying type of `fromReader527`:
30-
fromReader527 := sourceCQL.(io.Reader)
31-
32-
// Call the function that transfers the taint
33-
// from the parameter `fromReader527` to result `intoReader503`
34-
// (`intoReader503` is now tainted).
35-
intoReader503 := tar.NewReader(fromReader527)
36-
37-
// Return the tainted `intoReader503`:
38-
return intoReader503
18+
fromReader518 := sourceCQL.(io.Reader)
19+
intoReader650 := tar.NewReader(fromReader518)
20+
return intoReader650
3921
}
4022

4123
func TaintStepTest_ArchiveTarNewWriter_B0I0O0(sourceCQL interface{}) interface{} {
42-
// The flow is from `fromWriter907` into `intoWriter317`.
43-
44-
// Assume that `sourceCQL` has the underlying type of `fromWriter907`:
45-
fromWriter907 := sourceCQL.(*tar.Writer)
46-
47-
// Declare `intoWriter317` variable:
48-
var intoWriter317 io.Writer
49-
50-
// Call the function that will transfer the taint
51-
// from the result `intermediateCQL` to parameter `intoWriter317`:
52-
intermediateCQL := tar.NewWriter(intoWriter317)
53-
54-
// Extra step (`fromWriter907` taints `intermediateCQL`, which taints `intoWriter317`:
55-
link(fromWriter907, intermediateCQL)
56-
57-
// Return the tainted `intoWriter317`:
58-
return intoWriter317
24+
fromWriter784 := sourceCQL.(*tar.Writer)
25+
var intoWriter957 io.Writer
26+
intermediateCQL := tar.NewWriter(intoWriter957)
27+
link(fromWriter784, intermediateCQL)
28+
return intoWriter957
5929
}
6030

6131
func TaintStepTest_ArchiveTarHeaderFileInfo_B0I0O0(sourceCQL interface{}) interface{} {
62-
// The flow is from `fromHeader460` into `intoFileInfo402`.
63-
64-
// Assume that `sourceCQL` has the underlying type of `fromHeader460`:
65-
fromHeader460 := sourceCQL.(tar.Header)
66-
67-
// Call the method that transfers the taint
68-
// from the receiver `fromHeader460` to the result `intoFileInfo402`
69-
// (`intoFileInfo402` is now tainted).
70-
intoFileInfo402 := fromHeader460.FileInfo()
71-
72-
// Return the tainted `intoFileInfo402`:
73-
return intoFileInfo402
32+
fromHeader520 := sourceCQL.(tar.Header)
33+
intoFileInfo443 := fromHeader520.FileInfo()
34+
return intoFileInfo443
7435
}
7536

7637
func TaintStepTest_ArchiveTarReaderNext_B0I0O0(sourceCQL interface{}) interface{} {
77-
// The flow is from `fromReader994` into `intoHeader183`.
78-
79-
// Assume that `sourceCQL` has the underlying type of `fromReader994`:
80-
fromReader994 := sourceCQL.(tar.Reader)
81-
82-
// Call the method that transfers the taint
83-
// from the receiver `fromReader994` to the result `intoHeader183`
84-
// (`intoHeader183` is now tainted).
85-
intoHeader183, _ := fromReader994.Next()
86-
87-
// Return the tainted `intoHeader183`:
88-
return intoHeader183
38+
fromReader127 := sourceCQL.(tar.Reader)
39+
intoHeader483, _ := fromReader127.Next()
40+
return intoHeader483
8941
}
9042

9143
func TaintStepTest_ArchiveTarReaderRead_B0I0O0(sourceCQL interface{}) interface{} {
92-
// The flow is from `fromReader746` into `intoByte905`.
93-
94-
// Assume that `sourceCQL` has the underlying type of `fromReader746`:
95-
fromReader746 := sourceCQL.(tar.Reader)
96-
97-
// Declare `intoByte905` variable:
98-
var intoByte905 []byte
99-
100-
// Call the method that transfers the taint
101-
// from the receiver `fromReader746` to the argument `intoByte905`
102-
// (`intoByte905` is now tainted).
103-
fromReader746.Read(intoByte905)
104-
105-
// Return the tainted `intoByte905`:
106-
return intoByte905
44+
fromReader989 := sourceCQL.(tar.Reader)
45+
var intoByte982 []byte
46+
fromReader989.Read(intoByte982)
47+
return intoByte982
10748
}
10849

10950
func TaintStepTest_ArchiveTarWriterWrite_B0I0O0(sourceCQL interface{}) interface{} {
110-
// The flow is from `fromByte262` into `intoWriter837`.
111-
112-
// Assume that `sourceCQL` has the underlying type of `fromByte262`:
113-
fromByte262 := sourceCQL.([]byte)
114-
115-
// Declare `intoWriter837` variable:
116-
var intoWriter837 tar.Writer
117-
118-
// Call the method that transfers the taint
119-
// from the parameter `fromByte262` to the receiver `intoWriter837`
120-
// (`intoWriter837` is now tainted).
121-
intoWriter837.Write(fromByte262)
122-
123-
// Return the tainted `intoWriter837`:
124-
return intoWriter837
51+
fromByte417 := sourceCQL.([]byte)
52+
var intoWriter584 tar.Writer
53+
intoWriter584.Write(fromByte417)
54+
return intoWriter584
12555
}
12656

12757
func TaintStepTest_ArchiveTarWriterWriteHeader_B0I0O0(sourceCQL interface{}) interface{} {
128-
// The flow is from `fromHeader798` into `intoWriter568`.
129-
130-
// Assume that `sourceCQL` has the underlying type of `fromHeader798`:
131-
fromHeader798 := sourceCQL.(*tar.Header)
132-
133-
// Declare `intoWriter568` variable:
134-
var intoWriter568 tar.Writer
135-
136-
// Call the method that transfers the taint
137-
// from the parameter `fromHeader798` to the receiver `intoWriter568`
138-
// (`intoWriter568` is now tainted).
139-
intoWriter568.WriteHeader(fromHeader798)
140-
141-
// Return the tainted `intoWriter568`:
142-
return intoWriter568
58+
fromHeader991 := sourceCQL.(*tar.Header)
59+
var intoWriter881 tar.Writer
60+
intoWriter881.WriteHeader(fromHeader991)
61+
return intoWriter881
14362
}
14463

14564
func RunAllTaints_ArchiveTar() {
14665
{
147-
// Create a new source:
148-
source := newSource()
149-
// Run the taint scenario:
66+
source := newSource(0)
15067
out := TaintStepTest_ArchiveTarFileInfoHeader_B0I0O0(source)
151-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
152-
sink(out)
68+
sink(0, out)
15369
}
15470
{
155-
// Create a new source:
156-
source := newSource()
157-
// Run the taint scenario:
71+
source := newSource(1)
15872
out := TaintStepTest_ArchiveTarNewReader_B0I0O0(source)
159-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
160-
sink(out)
73+
sink(1, out)
16174
}
16275
{
163-
// Create a new source:
164-
source := newSource()
165-
// Run the taint scenario:
76+
source := newSource(2)
16677
out := TaintStepTest_ArchiveTarNewWriter_B0I0O0(source)
167-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
168-
sink(out)
78+
sink(2, out)
16979
}
17080
{
171-
// Create a new source:
172-
source := newSource()
173-
// Run the taint scenario:
81+
source := newSource(3)
17482
out := TaintStepTest_ArchiveTarHeaderFileInfo_B0I0O0(source)
175-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
176-
sink(out)
83+
sink(3, out)
17784
}
17885
{
179-
// Create a new source:
180-
source := newSource()
181-
// Run the taint scenario:
86+
source := newSource(4)
18287
out := TaintStepTest_ArchiveTarReaderNext_B0I0O0(source)
183-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
184-
sink(out)
88+
sink(4, out)
18589
}
18690
{
187-
// Create a new source:
188-
source := newSource()
189-
// Run the taint scenario:
91+
source := newSource(5)
19092
out := TaintStepTest_ArchiveTarReaderRead_B0I0O0(source)
191-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
192-
sink(out)
93+
sink(5, out)
19394
}
19495
{
195-
// Create a new source:
196-
source := newSource()
197-
// Run the taint scenario:
96+
source := newSource(6)
19897
out := TaintStepTest_ArchiveTarWriterWrite_B0I0O0(source)
199-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
200-
sink(out)
98+
sink(6, out)
20199
}
202100
{
203-
// Create a new source:
204-
source := newSource()
205-
// Run the taint scenario:
101+
source := newSource(7)
206102
out := TaintStepTest_ArchiveTarWriterWriteHeader_B0I0O0(source)
207-
// If the taint step(s) succeeded, then `out` is tainted and will be sink-able here:
208-
sink(out)
103+
sink(7, out)
209104
}
210105
}

0 commit comments

Comments
 (0)