Skip to content

Commit 4bcc425

Browse files
author
Paolo Tranquilli
committed
Merge branch 'main' into redsun82/rust-perf-measures
2 parents 50c917d + bd56a35 commit 4bcc425

File tree

147 files changed

+4585
-1107
lines changed

Some content is hidden

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

147 files changed

+4585
-1107
lines changed

.vscode/tasks.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,93 @@
3838
"command": "${config:python.pythonPath}",
3939
},
4040
"problemMatcher": []
41+
},
42+
{
43+
"label": "Create query change note",
44+
"type": "process",
45+
"command": "python3",
46+
"args": [
47+
"misc/scripts/create-change-note.py",
48+
"${input:language}",
49+
"src",
50+
"${input:name}",
51+
"${input:categoryQuery}"
52+
],
53+
"presentation": {
54+
"reveal": "never",
55+
"close": true
56+
},
57+
"problemMatcher": []
58+
},
59+
{
60+
"label": "Create library change note",
61+
"type": "process",
62+
"command": "python3",
63+
"args": [
64+
"misc/scripts/create-change-note.py",
65+
"${input:language}",
66+
"lib",
67+
"${input:name}",
68+
"${input:categoryLibrary}"
69+
],
70+
"presentation": {
71+
"reveal": "never",
72+
"close": true
73+
},
74+
"problemMatcher": []
75+
}
76+
],
77+
"inputs": [
78+
{
79+
"type": "pickString",
80+
"id": "language",
81+
"description": "Language",
82+
"options":
83+
[
84+
"go",
85+
"java",
86+
"javascript",
87+
"cpp",
88+
"csharp",
89+
"python",
90+
"ruby",
91+
"rust",
92+
"swift",
93+
]
94+
},
95+
{
96+
"type": "promptString",
97+
"id": "name",
98+
"description": "Short name (kebab-case)"
99+
},
100+
{
101+
"type": "pickString",
102+
"id": "categoryQuery",
103+
"description": "Category (query change)",
104+
"options":
105+
[
106+
"breaking",
107+
"deprecated",
108+
"newQuery",
109+
"queryMetadata",
110+
"majorAnalysis",
111+
"minorAnalysis",
112+
"fix",
113+
]
114+
},
115+
{
116+
"type": "pickString",
117+
"id": "categoryLibrary",
118+
"description": "Category (library change)",
119+
"options":
120+
[
121+
"breaking",
122+
"deprecated",
123+
"feature",
124+
"majorAnalysis",
125+
"minorAnalysis",
126+
"fix",
127+
]
41128
}
42129
]
43130
}

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -793,28 +793,27 @@ private Element interpretElement0(
793793
) {
794794
(
795795
// Non-member functions
796-
elementSpec(namespace, type, subtypes, name, signature, _) and
796+
funcHasQualifiedName(result, namespace, name) and
797797
subtypes = false and
798798
type = "" and
799799
(
800800
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature)
801801
or
802802
signature = "" and
803-
elementSpec(namespace, type, subtypes, name, "", _) and
804-
funcHasQualifiedName(result, namespace, name)
803+
elementSpec(namespace, type, subtypes, name, signature, _)
805804
)
806805
or
807806
// Member functions
808807
exists(Class namedClass, Class classWithMethod |
808+
hasClassAndName(classWithMethod, result, name) and
809+
classHasQualifiedName(namedClass, namespace, type)
810+
|
809811
(
810-
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature) and
811-
hasClassAndName(classWithMethod, result, name)
812+
elementSpecMatchesSignature(result, namespace, type, subtypes, name, signature)
812813
or
813814
signature = "" and
814-
elementSpec(namespace, type, subtypes, name, "", _) and
815-
hasClassAndName(classWithMethod, result, name)
815+
elementSpec(namespace, type, subtypes, name, "", _)
816816
) and
817-
classHasQualifiedName(namedClass, namespace, type) and
818817
(
819818
// member declared in the named type or a subtype of it
820819
subtypes = true and
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
<!DOCTYPE qhelp SYSTEM "qhelp.dtd">
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
24
<qhelp>
5+
36
<overview>
4-
<p>The <code>free</code> function, which deallocates heap memory, may accept a NULL pointer and take no action. Therefore, it is unnecessary to check its argument for the value of NULL before a function call to <code>free</code>. As such, these guards may hinder performance and readability.</p>
7+
<p>The <code>free</code> function, which deallocates heap memory, may accept a NULL pointer and take no action. Therefore, it is unnecessary to check the argument for the value of NULL before a function call to <code>free</code>. As such, these guards may hinder performance and readability.</p>
58
</overview>
9+
610
<recommendation>
7-
<p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the <code>if</code> condition preceeding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p>
11+
<p>A function call to <code>free</code> should not depend upon the value of its argument. Delete the condition preceding a function call to <code>free</code> when its only purpose is to check the value of the pointer to be freed.</p>
812
</recommendation>
13+
914
<example>
1015
<sample src = "GuardedFree.cpp" />
16+
17+
<p>In this example, the condition checking the value of <code>foo</code> can be deleted.</p>
18+
1119
</example>
20+
1221
<references>
1322
<li>
1423
The Open Group Base Specifications Issue 7, 2018 Edition:
15-
<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a>
24+
<a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html">free - free allocated memory</a>.
1625
</li>
1726
</references>
18-
</qhelp>
27+
28+
</qhelp>

cpp/ql/src/experimental/Best Practices/GuardedFree.ql renamed to cpp/ql/src/Best Practices/GuardedFree.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @id cpp/guarded-free
99
* @tags maintainability
1010
* readability
11-
* experimental
1211
*/
1312

1413
import cpp
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: newQuery
3+
---
4+
* Added a new high-precision quality query, `cpp/guarded-free`, which detects useless NULL pointer checks before calls to `free`. A variation of this query was originally contributed as an [experimental query by @mario-campos](https://github.com/github/codeql/pull/16331).

cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/GuardedFree.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/ql/test/library-tests/dataflow/taint-tests/format.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,10 @@ void test_format() {
164164

165165
auto s2 = std::format(string::source());
166166
sink(s2); // $ ir MISSING: ast
167+
}
168+
169+
void test(std::format_string s) {
170+
int x = source();
171+
int y = std::same_signature_as_format_but_different_name(s, x);
172+
sink(y); // clean
167173
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
451451
| format.cpp:162:24:162:27 | {} | format.cpp:162:24:162:27 | call to basic_format_string | TAINT |
452452
| format.cpp:165:13:165:23 | call to format | format.cpp:166:8:166:9 | s2 | |
453453
| format.cpp:165:25:165:38 | call to source | format.cpp:165:25:165:40 | call to basic_format_string | TAINT |
454+
| format.cpp:169:30:169:30 | s | format.cpp:171:60:171:60 | s | |
455+
| format.cpp:170:11:170:16 | call to source | format.cpp:171:63:171:63 | x | |
456+
| format.cpp:171:11:171:58 | call to same_signature_as_format_but_different_name | format.cpp:172:8:172:8 | y | |
454457
| map.cpp:21:28:21:28 | call to pair | map.cpp:23:2:23:2 | a | |
455458
| map.cpp:21:28:21:28 | call to pair | map.cpp:24:7:24:7 | a | |
456459
| map.cpp:21:28:21:28 | call to pair | map.cpp:25:7:25:7 | a | |

cpp/ql/test/library-tests/dataflow/taint-tests/stl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,9 @@ namespace std {
676676
using format_string = basic_format_string<char>; // simplified from `char, std::type_identity_t<Args>...`
677677

678678
template<class... Args> string format( format_string fmt, Args&&... args );
679+
680+
// This function has the same signature as `format`, but a different name. It should NOT be able to use
681+
// the model for `format`.
682+
template <typename... Args>
683+
int same_signature_as_format_but_different_name(format_string, Args &&...args);
679684
}

0 commit comments

Comments
 (0)