Skip to content

Commit f5e33ac

Browse files
committed
Merge remote-tracking branch 'origin/main' into python/support-grouped-exceptions
2 parents ad6ed2f + b5b0a64 commit f5e33ac

File tree

169 files changed

+2634
-3460
lines changed

Some content is hidden

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

169 files changed

+2634
-3460
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `ArgvSource` flow source now uses the second parameter of `main` as its source instead of the uses of this parameter.

cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private class ArgvSource extends LocalFlowSource {
9292
exists(Function main, Parameter argv |
9393
main.hasGlobalName("main") and
9494
main.getParameter(1) = argv and
95-
this.asExpr() = argv.getAnAccess()
95+
this.asParameter() = argv
9696
)
9797
}
9898

cpp/ql/src/AlertSuppression.ql

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,35 @@
55
* @id cpp/alert-suppression
66
*/
77

8-
import cpp
9-
10-
/**
11-
* An alert suppression comment.
12-
*/
13-
class SuppressionComment extends Comment {
14-
string annotation;
15-
string text;
16-
17-
SuppressionComment() {
18-
(
19-
this instanceof CppStyleComment and
20-
// strip the beginning slashes
21-
text = this.getContents().suffix(2)
22-
or
23-
this instanceof CStyleComment and
24-
// strip both the beginning /* and the end */ the comment
25-
exists(string text0 |
26-
text0 = this.getContents().suffix(2) and
27-
text = text0.prefix(text0.length() - 2)
28-
) and
29-
// The /* */ comment must be a single-line comment
30-
not text.matches("%\n%")
8+
private import codeql.suppression.AlertSuppression as AS
9+
private import semmle.code.cpp.Element
10+
11+
class SingleLineComment extends Comment {
12+
private string text;
13+
14+
SingleLineComment() {
15+
this instanceof CppStyleComment and
16+
// strip the beginning slashes
17+
text = this.getContents().suffix(2)
18+
or
19+
this instanceof CStyleComment and
20+
// strip both the beginning /* and the end */ the comment
21+
exists(string text0 |
22+
text0 = this.getContents().suffix(2) and
23+
text = text0.prefix(text0.length() - 2)
3124
) and
32-
(
33-
// match `lgtm[...]` anywhere in the comment
34-
annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _)
35-
or
36-
// match `lgtm` at the start of the comment and after semicolon
37-
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim()
38-
)
25+
// The /* */ comment must be a single-line comment
26+
not text.matches("%\n%")
3927
}
4028

41-
/** Gets the text in this comment, excluding the leading //. */
42-
string getText() { result = text }
43-
44-
/** Gets the suppression annotation in this comment. */
45-
string getAnnotation() { result = annotation }
46-
47-
/**
48-
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
49-
* to column `endcolumn` of line `endline` in file `filepath`.
50-
*/
51-
predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
52-
this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and
53-
startcolumn = 1
54-
}
55-
56-
/** Gets the scope of this suppression. */
57-
SuppressionScope getScope() { result = this }
58-
}
59-
60-
/**
61-
* The scope of an alert suppression comment.
62-
*/
63-
class SuppressionScope extends ElementBase instanceof SuppressionComment {
64-
/**
65-
* Holds if this element is at the specified location.
66-
* The location spans column `startcolumn` of line `startline` to
67-
* column `endcolumn` of line `endline` in file `filepath`.
68-
* For more information, see
69-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
70-
*/
7129
predicate hasLocationInfo(
7230
string filepath, int startline, int startcolumn, int endline, int endcolumn
7331
) {
74-
super.covers(filepath, startline, startcolumn, endline, endcolumn)
32+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
7533
}
34+
35+
/** Gets the text in this comment, excluding the leading //. */
36+
string getText() { result = text }
7637
}
7738

78-
from SuppressionComment c
79-
select c, // suppression comment
80-
c.getText(), // text of suppression comment (excluding delimiters)
81-
c.getAnnotation(), // text of suppression annotation
82-
c.getScope() // scope of suppression
39+
import AS::Make<SingleLineComment>

cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class TaintedPathConfiguration extends TaintTracking::Configuration {
9191
)
9292
}
9393

94-
override predicate isSanitizerIn(DataFlow::Node node) { this.isSource(node) }
95-
9694
override predicate isSanitizer(DataFlow::Node node) {
9795
node.asExpr().(Call).getTarget().getUnspecifiedType() instanceof ArithmeticType
9896
or

cpp/ql/src/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ groups:
66
dependencies:
77
codeql/cpp-all: ${workspace}
88
codeql/suite-helpers: ${workspace}
9+
codeql/util: ${workspace}
910
suites: codeql-suites
1011
extractor: cpp
1112
defaultSuiteFile: codeql-suites/cpp-code-scanning.qls
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
edges
2-
| test.cpp:23:20:23:23 | argv | test.cpp:29:13:29:20 | (const char *)... |
3-
| test.cpp:23:20:23:23 | argv | test.cpp:29:13:29:20 | filePath |
2+
| test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | (const char *)... |
3+
| test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath |
44
nodes
5-
| test.cpp:23:20:23:23 | argv | semmle.label | argv |
5+
| test.cpp:22:27:22:30 | argv | semmle.label | argv |
66
| test.cpp:29:13:29:20 | (const char *)... | semmle.label | (const char *)... |
77
| test.cpp:29:13:29:20 | filePath | semmle.label | filePath |
88
subpaths
99
#select
10-
| test.cpp:29:13:29:20 | (const char *)... | test.cpp:23:20:23:23 | argv | test.cpp:29:13:29:20 | (const char *)... | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
11-
| test.cpp:29:13:29:20 | filePath | test.cpp:23:20:23:23 | argv | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
10+
| test.cpp:29:13:29:20 | (const char *)... | test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | (const char *)... | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |
11+
| test.cpp:29:13:29:20 | filePath | test.cpp:22:27:22:30 | argv | test.cpp:29:13:29:20 | filePath | Using user-supplied data in a `wordexp` command, without disabling command substitution, can make code vulnerable to command injection. |

0 commit comments

Comments
 (0)