Skip to content

Commit a16e19a

Browse files
authored
Merge pull request #22127 from owen-mc/cpp/convert-qlref-inline-expectations
C++: Convert qlref tests to inline expectations
2 parents 69ed2da + 19745e1 commit a16e19a

719 files changed

Lines changed: 4116 additions & 3825 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.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
jsf/4.13 Functions/AV Rule 107.ql
1+
query: jsf/4.13 Functions/AV Rule 107.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Best Practices/Hiding/LocalVariableHidesGlobalVariable.ql
1+
query: Best Practices/Hiding/LocalVariableHidesGlobalVariable.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

cpp/ql/test/examples/BadLocking/UnintendedDeclaration.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void test1()
4848

4949
void test2()
5050
{
51-
Lock<Mutex> myLock(); // BAD (interpreted as a function declaration, this does nothing)
51+
Lock<Mutex> myLock(); // $ Alert[cpp/function-in-block] // BAD (interpreted as a function declaration, this does nothing)
5252

5353
// ...
5454
}
@@ -62,14 +62,14 @@ void test3()
6262

6363
void test4()
6464
{
65-
Lock<Mutex>(myMutex); // BAD (creates an uninitialized variable called `myMutex`, probably not intended)
65+
Lock<Mutex>(myMutex); // $ Alert[cpp/local-variable-hides-global-variable] // BAD (creates an uninitialized variable called `myMutex`, probably not intended)
6666

6767
// ...
6868
}
6969

7070
void test5()
7171
{
72-
Lock<Mutex> myLock(Mutex); // BAD (interpreted as a function declaration, this does nothing)
72+
Lock<Mutex> myLock(Mutex); // $ Alert[cpp/function-in-block] // BAD (interpreted as a function declaration, this does nothing)
7373

7474
// ...
7575
}
@@ -86,7 +86,7 @@ class MyTestClass
8686

8787
void test7()
8888
{
89-
Lock<Mutex>(memberMutex); // BAD (creates an uninitialized variable called `memberMutex`, probably not intended) [NOT DETECTED]
89+
Lock<Mutex>(memberMutex); // $ MISSING: Alert // BAD (creates an uninitialized variable called `memberMutex`, probably not intended) [NOT DETECTED]
9090

9191
// ...
9292
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/Security/CWE/CWE-020/NoCheckBeforeUnsafePutUser.ql
1+
query: experimental/Security/CWE/CWE-020/NoCheckBeforeUnsafePutUser.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-020/NoCheckBeforeUnsafePutUser/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void test1(int p)
1919
{
2020
sys_somesystemcall(&p);
2121

22-
unsafe_put_user(123, &p); // BAD [NOT DETECTED]
22+
unsafe_put_user(123, &p); // $ MISSING: Alert // BAD [NOT DETECTED]
2323
}
2424

2525
void test2(int p)
@@ -40,7 +40,7 @@ void test3()
4040

4141
sys_somesystemcall(&v);
4242

43-
unsafe_put_user(123, &v); // BAD [NOT DETECTED]
43+
unsafe_put_user(123, &v); // $ MISSING: Alert // BAD [NOT DETECTED]
4444
}
4545

4646
void test4()
@@ -68,7 +68,7 @@ void test5()
6868

6969
sys_somesystemcall(&myData);
7070

71-
unsafe_put_user(123, &(myData.x)); // BAD [NOT DETECTED]
71+
unsafe_put_user(123, &(myData.x)); // $ MISSING: Alert // BAD [NOT DETECTED]
7272
}
7373

7474
void test6()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
1+
query: experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-020/semmle/tests/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ void workFunction_0(char *s) {
33
char buf[80], buf1[8];
44
if(len<0) return;
55
memset(buf,0,len); //GOOD
6-
memset(buf1,0,len1); //BAD
6+
memset(buf1,0,len1); // $ Alert //BAD
77
if(len1<0) return;
88
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/Security/CWE/CWE-078/WordexpTainted.ql
1+
query: experimental/Security/CWE/CWE-078/WordexpTainted.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-078/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ enum {
1919

2020
int wordexp(const char *restrict s, wordexp_t *restrict p, int flags);
2121

22-
int main(int argc, char** argv) {
22+
int main(int argc, char** argv) { // $ Source
2323
char *filePath = argv[2];
2424

2525
{
2626
// BAD: the user string is injected directly into `wordexp` which performs command substitution
2727

2828
wordexp_t we;
29-
wordexp(filePath, &we, 0);
29+
wordexp(filePath, &we, 0); // $ Alert
3030
}
3131

3232
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
experimental/Security/CWE/CWE-1041/FindWrapperFunctions.ql
1+
query: experimental/Security/CWE/CWE-1041/FindWrapperFunctions.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)