Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7a92e5

Browse files
committed
Merge branch 'main' into swap
2 parents 9c77d3c + ceaaac2 commit d7a92e5

145 files changed

Lines changed: 13505 additions & 7914 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/generate-query-help-docs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
name: Generate CodeQL query help documentation using Sphinx
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
description:
7+
description: A description of the purpose of this job. For human consumption.
8+
required: false
49
push:
510
branches:
6-
- main
7-
- 'rc/**'
811
- 'lgtm.com'
912
pull_request:
1013
paths:
1114
- '.github/workflows/generate-query-help-docs.yml'
1215
- 'docs/codeql/query-help/**'
13-
16+
1417
jobs:
1518
build:
1619
runs-on: ubuntu-latest
1720
steps:
1821
- name: Clone github/codeql
1922
uses: actions/checkout@v2
2023
with:
21-
path: codeql
24+
path: codeql
2225
- name: Clone github/codeql-go
2326
uses: actions/checkout@v2
2427
with:

cpp/ql/src/Best Practices/Magic Constants/MagicConstants.qll

Lines changed: 36 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -8,168 +8,41 @@ import semmle.code.cpp.AutogeneratedFile
88
predicate trivialPositiveIntValue(string s) {
99
// Small numbers
1010
s = [0 .. 20].toString() or
11-
// Popular powers of two (decimal)
12-
s = "16" or
13-
s = "24" or
14-
s = "32" or
15-
s = "64" or
16-
s = "128" or
17-
s = "256" or
18-
s = "512" or
19-
s = "1024" or
20-
s = "2048" or
21-
s = "4096" or
22-
s = "16384" or
23-
s = "32768" or
24-
s = "65536" or
25-
s = "1048576" or
26-
s = "2147483648" or
27-
s = "4294967296" or
28-
// Popular powers of two, minus one (decimal)
29-
s = "15" or
30-
s = "31" or
31-
s = "63" or
32-
s = "127" or
33-
s = "255" or
34-
s = "511" or
35-
s = "1023" or
36-
s = "2047" or
37-
s = "4095" or
38-
s = "16383" or
39-
s = "32767" or
40-
s = "65535" or
41-
s = "1048577" or
42-
s = "2147483647" or
43-
s = "4294967295" or
44-
// Popular powers of two (32-bit hex)
45-
s = "0x00000001" or
46-
s = "0x00000002" or
47-
s = "0x00000004" or
48-
s = "0x00000008" or
49-
s = "0x00000010" or
50-
s = "0x00000020" or
51-
s = "0x00000040" or
52-
s = "0x00000080" or
53-
s = "0x00000100" or
54-
s = "0x00000200" or
55-
s = "0x00000400" or
56-
s = "0x00000800" or
57-
s = "0x00001000" or
58-
s = "0x00002000" or
59-
s = "0x00004000" or
60-
s = "0x00008000" or
61-
s = "0x00010000" or
62-
s = "0x00020000" or
63-
s = "0x00040000" or
64-
s = "0x00080000" or
65-
s = "0x00100000" or
66-
s = "0x00200000" or
67-
s = "0x00400000" or
68-
s = "0x00800000" or
69-
s = "0x01000000" or
70-
s = "0x02000000" or
71-
s = "0x04000000" or
72-
s = "0x08000000" or
73-
s = "0x10000000" or
74-
s = "0x20000000" or
75-
s = "0x40000000" or
76-
s = "0x80000000" or
77-
// Popular powers of two, minus one (32-bit hex)
78-
s = "0x00000001" or
79-
s = "0x00000003" or
80-
s = "0x00000007" or
81-
s = "0x0000000f" or
82-
s = "0x0000001f" or
83-
s = "0x0000003f" or
84-
s = "0x0000007f" or
85-
s = "0x000000ff" or
86-
s = "0x000001ff" or
87-
s = "0x000003ff" or
88-
s = "0x000007ff" or
89-
s = "0x00000fff" or
90-
s = "0x00001fff" or
91-
s = "0x00003fff" or
92-
s = "0x00007fff" or
93-
s = "0x0000ffff" or
94-
s = "0x0001ffff" or
95-
s = "0x0003ffff" or
96-
s = "0x0007ffff" or
97-
s = "0x000fffff" or
98-
s = "0x001fffff" or
99-
s = "0x003fffff" or
100-
s = "0x007fffff" or
101-
s = "0x00ffffff" or
102-
s = "0x01ffffff" or
103-
s = "0x03ffffff" or
104-
s = "0x07ffffff" or
105-
s = "0x0fffffff" or
106-
s = "0x1fffffff" or
107-
s = "0x3fffffff" or
108-
s = "0x7fffffff" or
109-
s = "0xffffffff" or
110-
// Popular powers of two (16-bit hex)
111-
s = "0x0001" or
112-
s = "0x0002" or
113-
s = "0x0004" or
114-
s = "0x0008" or
115-
s = "0x0010" or
116-
s = "0x0020" or
117-
s = "0x0040" or
118-
s = "0x0080" or
119-
s = "0x0100" or
120-
s = "0x0200" or
121-
s = "0x0400" or
122-
s = "0x0800" or
123-
s = "0x1000" or
124-
s = "0x2000" or
125-
s = "0x4000" or
126-
s = "0x8000" or
127-
// Popular powers of two, minus one (16-bit hex)
128-
s = "0x0001" or
129-
s = "0x0003" or
130-
s = "0x0007" or
131-
s = "0x000f" or
132-
s = "0x001f" or
133-
s = "0x003f" or
134-
s = "0x007f" or
135-
s = "0x00ff" or
136-
s = "0x01ff" or
137-
s = "0x03ff" or
138-
s = "0x07ff" or
139-
s = "0x0fff" or
140-
s = "0x1fff" or
141-
s = "0x3fff" or
142-
s = "0x7fff" or
143-
s = "0xffff" or
144-
// Popular powers of two (8-bit hex)
145-
s = "0x01" or
146-
s = "0x02" or
147-
s = "0x04" or
148-
s = "0x08" or
149-
s = "0x10" or
150-
s = "0x20" or
151-
s = "0x40" or
152-
s = "0x80" or
153-
// Popular powers of two, minus one (8-bit hex)
154-
s = "0x01" or
155-
s = "0x03" or
156-
s = "0x07" or
157-
s = "0x0f" or
158-
s = "0x1f" or
159-
s = "0x3f" or
160-
s = "0x7f" or
161-
s = "0xff" or
162-
s = "0x00" or
163-
// Powers of ten
164-
s = "10" or
165-
s = "100" or
166-
s = "1000" or
167-
s = "10000" or
168-
s = "100000" or
169-
s = "1000000" or
170-
s = "10000000" or
171-
s = "100000000" or
172-
s = "1000000000"
11+
s =
12+
[
13+
// Popular powers of two (decimal)
14+
"16", "24", "32", "64", "128", "256", "512", "1024", "2048", "4096", "16384", "32768",
15+
"65536", "1048576", "2147483648", "4294967296",
16+
// Popular powers of two, minus one (decimal)
17+
"15", "31", "63", "127", "255", "511", "1023", "2047", "4095", "16383", "32767", "65535",
18+
"1048577", "2147483647", "4294967295",
19+
// Popular powers of two (32-bit hex)
20+
"0x00000001", "0x00000002", "0x00000004", "0x00000008", "0x00000010", "0x00000020",
21+
"0x00000040", "0x00000080", "0x00000100", "0x00000200", "0x00000400", "0x00000800",
22+
"0x00001000", "0x00002000", "0x00004000", "0x00008000", "0x00010000", "0x00020000",
23+
"0x00040000", "0x00080000", "0x00100000", "0x00200000", "0x00400000", "0x00800000",
24+
"0x01000000", "0x02000000", "0x04000000", "0x08000000", "0x10000000", "0x20000000",
25+
"0x40000000", "0x80000000",
26+
// Popular powers of two, minus one (32-bit hex)
27+
"0x00000001", "0x00000003", "0x00000007", "0x0000000f", "0x0000001f", "0x0000003f",
28+
"0x0000007f", "0x000000ff", "0x000001ff", "0x000003ff", "0x000007ff", "0x00000fff",
29+
"0x00001fff", "0x00003fff", "0x00007fff", "0x0000ffff", "0x0001ffff", "0x0003ffff",
30+
"0x0007ffff", "0x000fffff", "0x001fffff", "0x003fffff", "0x007fffff", "0x00ffffff",
31+
"0x01ffffff", "0x03ffffff", "0x07ffffff", "0x0fffffff", "0x1fffffff", "0x3fffffff",
32+
"0x7fffffff", "0xffffffff",
33+
// Popular powers of two (16-bit hex)
34+
"0x0001", "0x0002", "0x0004", "0x0008", "0x0010", "0x0020", "0x0040", "0x0080", "0x0100",
35+
"0x0200", "0x0400", "0x0800", "0x1000", "0x2000", "0x4000", "0x8000",
36+
// Popular powers of two, minus one (16-bit hex)
37+
"0x0001", "0x0003", "0x0007", "0x000f", "0x001f", "0x003f", "0x007f", "0x00ff", "0x01ff",
38+
"0x03ff", "0x07ff", "0x0fff", "0x1fff", "0x3fff", "0x7fff", "0xffff",
39+
// Popular powers of two (8-bit hex)
40+
"0x01", "0x02", "0x04", "0x08", "0x10", "0x20", "0x40", "0x80",
41+
// Popular powers of two, minus one (8-bit hex)
42+
"0x01", "0x03", "0x07", "0x0f", "0x1f", "0x3f", "0x7f", "0xff", "0x00",
43+
// Powers of ten
44+
"10", "100", "1000", "10000", "100000", "1000000", "10000000", "100000000", "1000000000"
45+
]
17346
}
17447

17548
predicate trivialIntValue(string s) {
@@ -235,10 +108,7 @@ predicate joiningStringTrivial(Literal lit) {
235108
// understand (which is against the spirit of these queries).
236109
stringLiteral(lit) and
237110
exists(FunctionCall fc |
238-
(
239-
fc.getTarget().getName() = "operator+" or
240-
fc.getTarget().getName() = "operator<<"
241-
) and
111+
fc.getTarget().getName() = ["operator+", "operator<<"] and
242112
fc.getAnArgument().getAChild*() = lit
243113
) and
244114
lit.getValue().length() < 16

cpp/ql/src/DefaultOptions.qll

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ class Options extends string {
5959
predicate exits(Function f) {
6060
f.getAnAttribute().hasName("noreturn")
6161
or
62-
exists(string name | f.hasGlobalOrStdName(name) |
63-
name = "exit" or
64-
name = "_exit" or
65-
name = "abort" or
66-
name = "__assert_fail" or
67-
name = "longjmp" or
68-
name = "__builtin_unreachable"
69-
)
62+
f.hasGlobalOrStdName([
63+
"exit", "_exit", "abort", "__assert_fail", "longjmp", "__builtin_unreachable"
64+
])
7065
or
7166
CustomOptions::exits(f) // old Options.qll
7267
}

cpp/ql/src/JPL_C/LOC-2/Rule 05/HeapMemory.ql

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ class Initialization extends Function {
2121
}
2222

2323
class Allocation extends FunctionCall {
24-
Allocation() {
25-
exists(string name | name = this.getTarget().getName() |
26-
name = "malloc" or
27-
name = "calloc" or
28-
name = "alloca" or
29-
name = "sbrk" or
30-
name = "valloc"
31-
)
32-
}
24+
Allocation() { this.getTarget().getName() = ["malloc", "calloc", "alloca", "sbrk", "valloc"] }
3325
}
3426

3527
from Function f, Allocation a

cpp/ql/src/JPL_C/LOC-2/Rule 07/ThreadSafety.ql

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ import cpp
1313

1414
class ForbiddenCall extends FunctionCall {
1515
ForbiddenCall() {
16-
exists(string name | name = this.getTarget().getName() |
17-
name = "task_delay" or
18-
name = "taskDelay" or
19-
name = "sleep" or
20-
name = "nanosleep" or
21-
name = "clock_nanosleep"
22-
)
16+
this.getTarget().getName() =
17+
["task_delay", "taskDelay", "sleep", "nanosleep", "clock_nanosleep"]
2318
}
2419
}
2520

cpp/ql/src/JPL_C/LOC-2/Rule 09/Semaphores.qll

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import cpp
66

77
class SemaphoreCreation extends FunctionCall {
88
SemaphoreCreation() {
9-
exists(string name | name = this.getTarget().getName() |
10-
name = "semBCreate" or
11-
name = "semMCreate" or
12-
name = "semCCreate" or
13-
name = "semRWCreate"
14-
)
9+
this.getTarget().getName() = ["semBCreate", "semMCreate", "semCCreate", "semRWCreate"]
1510
}
1611

1712
Variable getSemaphore() { result.getAnAccess() = this.getParent().(Assignment).getLValue() }
@@ -72,11 +67,7 @@ class SemaphoreGive extends UnlockOperation {
7267
}
7368

7469
class LockingPrimitive extends FunctionCall, LockOperation {
75-
LockingPrimitive() {
76-
exists(string name | name = this.getTarget().getName() |
77-
name = "taskLock" or name = "intLock" or name = "taskRtpLock"
78-
)
79-
}
70+
LockingPrimitive() { this.getTarget().getName() = ["taskLock", "intLock", "taskRtpLock"] }
8071

8172
override Function getLocked() { result = this.getTarget() }
8273

@@ -89,11 +80,7 @@ class LockingPrimitive extends FunctionCall, LockOperation {
8980
}
9081

9182
class UnlockingPrimitive extends FunctionCall, UnlockOperation {
92-
UnlockingPrimitive() {
93-
exists(string name | name = this.getTarget().getName() |
94-
name = "taskUnlock" or name = "intUnlock" or name = "taskRtpUnlock"
95-
)
96-
}
83+
UnlockingPrimitive() { this.getTarget().getName() = ["taskUnlock", "intUnlock", "taskRtpUnlock"] }
9784

9885
Function getLocked() { result = getMatchingLock().getLocked() }
9986

cpp/ql/src/JPL_C/LOC-3/Rule 17/BasicIntTypes.ql

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@
1212
import cpp
1313

1414
predicate allowedTypedefs(TypedefType t) {
15-
exists(string name | name = t.getName() |
16-
name = "I64" or
17-
name = "U64" or
18-
name = "I32" or
19-
name = "U32" or
20-
name = "I16" or
21-
name = "U16" or
22-
name = "I8" or
23-
name = "U8" or
24-
name = "F64" or
25-
name = "F32"
26-
)
15+
t.getName() = ["I64", "U64", "I32", "U32", "I16", "U16", "I8", "U8", "F64", "F32"]
2716
}
2817

2918
/**

cpp/ql/src/JPL_C/Tasks.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import cpp
55
*/
66
class Task extends Function {
77
Task() {
8-
exists(FunctionCall taskCreate, string name | name = "taskCreate" or name = "taskSpawn" |
9-
name = taskCreate.getTarget().getName() and
8+
exists(FunctionCall taskCreate |
9+
taskCreate.getTarget().getName() = ["taskCreate", "taskSpawn"] and
1010
this = taskCreate.getArgument(4).(AddressOfExpr).getAddressable()
1111
)
1212
}

0 commit comments

Comments
 (0)