Skip to content

Commit d205528

Browse files
committed
Add models for go 1.19's new atomic pointer typex
1 parent 8eb5d00 commit d205528

File tree

2 files changed

+128
-8
lines changed

2 files changed

+128
-8
lines changed

go/ql/lib/semmle/go/frameworks/stdlib/SyncAtomic.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ module SyncAtomic {
6969
FunctionOutput outp;
7070

7171
MethodModels() {
72-
// signature: func (*Value) Load() (x interface{})
73-
hasQualifiedName("sync/atomic", "Value", "Load") and
74-
(inp.isReceiver() and outp.isResult())
75-
or
76-
// signature: func (*Value) Store(x interface{})
77-
hasQualifiedName("sync/atomic", "Value", "Store") and
78-
(inp.isParameter(0) and outp.isReceiver())
72+
exists(string containerType | containerType = ["Value", "Pointer", "Uintptr"] |
73+
// signature: func (*Containertype) Load/Swap() (x containedtype)
74+
hasQualifiedName("sync/atomic", containerType, ["Load", "Swap"]) and
75+
(inp.isReceiver() and outp.isResult())
76+
or
77+
// signature: func (*Containertype) Store/Swap(x containedtype) [(x containedtype)]
78+
hasQualifiedName("sync/atomic", containerType, ["Store", "Swap"]) and
79+
(inp.isParameter(0) and outp.isReceiver())
80+
)
7981
}
8082

8183
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {

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

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Code generated by https://github.com/gagliardetto/codebox. DO NOT EDIT.
1+
// Code partially generated by https://github.com/gagliardetto/codebox, with manual additions
2+
// for atomic.Pointer and Uintptr, as well as atomic.Value's Swap method.
23

34
package main
45

@@ -99,6 +100,73 @@ func TaintStepTest_SyncAtomicValueStore_B0I0O0(sourceCQL interface{}) interface{
99100
return intoValue631
100101
}
101102

103+
func TaintStepTest_SyncAtomicValueSwap(sourceCQL interface{}) interface{} {
104+
fromInterface598 := sourceCQL.(interface{})
105+
var intoValue631 atomic.Value
106+
intoValue631.Swap(fromInterface598)
107+
return intoValue631
108+
}
109+
110+
func TaintStepTest_SyncAtomicValueSwap2(sourceCQL interface{}) interface{} {
111+
fromValue246 := sourceCQL.(atomic.Value)
112+
intoInterface898 := fromValue246.Swap("clean")
113+
return intoInterface898
114+
}
115+
116+
func TaintStepTest_SyncAtomicPointerLoad_B0I0O0(sourceCQL interface{}) interface{} {
117+
fromValue246 := sourceCQL.(atomic.Pointer[string])
118+
intoInterface898 := fromValue246.Load()
119+
return intoInterface898
120+
}
121+
122+
func TaintStepTest_SyncAtomicPointerStore_B0I0O0(sourceCQL interface{}) interface{} {
123+
fromInterface598 := sourceCQL.(*string)
124+
var intoValue631 atomic.Pointer[string]
125+
intoValue631.Store(fromInterface598)
126+
return intoValue631
127+
}
128+
129+
func TaintStepTest_SyncAtomicPointerSwap(sourceCQL interface{}) interface{} {
130+
fromInterface598 := sourceCQL.(*string)
131+
var intoValue631 atomic.Pointer[string]
132+
intoValue631.Swap(fromInterface598)
133+
return intoValue631
134+
}
135+
136+
func TaintStepTest_SyncAtomicPointerSwap2(sourceCQL interface{}) interface{} {
137+
fromValue246 := sourceCQL.(atomic.Pointer[string])
138+
clean := "Clean"
139+
intoInterface898 := fromValue246.Swap(&clean)
140+
return intoInterface898
141+
}
142+
143+
func TaintStepTest_SyncAtomicUintptrLoad_B0I0O0(sourceCQL interface{}) interface{} {
144+
fromValue246 := sourceCQL.(atomic.Uintptr)
145+
intoInterface898 := fromValue246.Load()
146+
return intoInterface898
147+
}
148+
149+
func TaintStepTest_SyncAtomicUintptrStore_B0I0O0(sourceCQL interface{}) interface{} {
150+
fromInterface598 := sourceCQL.(uintptr)
151+
var intoValue631 atomic.Uintptr
152+
intoValue631.Store(fromInterface598)
153+
return intoValue631
154+
}
155+
156+
func TaintStepTest_SyncAtomicUintptrSwap(sourceCQL interface{}) interface{} {
157+
fromInterface598 := sourceCQL.(uintptr)
158+
var intoValue631 atomic.Uintptr
159+
intoValue631.Swap(fromInterface598)
160+
return intoValue631
161+
}
162+
163+
func TaintStepTest_SyncAtomicUintptrSwap2(sourceCQL interface{}) interface{} {
164+
fromValue246 := sourceCQL.(atomic.Uintptr)
165+
clean := "Clean"
166+
intoInterface898 := fromValue246.Swap(uintptr(unsafe.Pointer(&clean)))
167+
return intoInterface898
168+
}
169+
102170
func RunAllTaints_SyncAtomic() {
103171
{
104172
source := newSource(0)
@@ -170,4 +238,54 @@ func RunAllTaints_SyncAtomic() {
170238
out := TaintStepTest_SyncAtomicValueStore_B0I0O0(source)
171239
sink(13, out)
172240
}
241+
{
242+
source := newSource(14)
243+
out := TaintStepTest_SyncAtomicValueSwap(source)
244+
sink(14, out)
245+
}
246+
{
247+
source := newSource(15)
248+
out := TaintStepTest_SyncAtomicValueSwap2(source)
249+
sink(15, out)
250+
}
251+
{
252+
source := newSource(16)
253+
out := TaintStepTest_SyncAtomicPointerLoad_B0I0O0(source)
254+
sink(16, out)
255+
}
256+
{
257+
source := newSource(17)
258+
out := TaintStepTest_SyncAtomicPointerStore_B0I0O0(source)
259+
sink(17, out)
260+
}
261+
{
262+
source := newSource(18)
263+
out := TaintStepTest_SyncAtomicPointerSwap(source)
264+
sink(18, out)
265+
}
266+
{
267+
source := newSource(19)
268+
out := TaintStepTest_SyncAtomicPointerSwap2(source)
269+
sink(19, out)
270+
}
271+
{
272+
source := newSource(20)
273+
out := TaintStepTest_SyncAtomicUintptrLoad_B0I0O0(source)
274+
sink(20, out)
275+
}
276+
{
277+
source := newSource(21)
278+
out := TaintStepTest_SyncAtomicUintptrStore_B0I0O0(source)
279+
sink(21, out)
280+
}
281+
{
282+
source := newSource(22)
283+
out := TaintStepTest_SyncAtomicUintptrSwap(source)
284+
sink(22, out)
285+
}
286+
{
287+
source := newSource(23)
288+
out := TaintStepTest_SyncAtomicUintptrSwap2(source)
289+
sink(23, out)
290+
}
173291
}

0 commit comments

Comments
 (0)