Skip to content

Commit 8ea152e

Browse files
committed
C++: Add change note
1 parent 0c31346 commit 8ea152e

File tree

8 files changed

+49932
-0
lines changed

8 files changed

+49932
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: feature
3+
---
4+
* New classes `TypeofType`, `TypeofExprType`, and `TypeofTypeType` were introduced, which represent the C23 `typeof` and `typeof_unqual` operators. The `TypeofExprType` class represents the variant taking an expression as its argument. The `TypeofTypeType` class represents the variant taking a type as its argument.
5+
* A new class `IntrinsicTransformedType` was introduced, which represents the type transforming intrinsics supported by clang, gcc, and MSVC.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace {
2+
class Data {
3+
public:
4+
template <typename U>
5+
int process1() {
6+
return data_ + 10;
7+
}
8+
9+
template <typename U>
10+
int process2(int data) {
11+
return data + 20;
12+
}
13+
14+
int process3() {
15+
return data_ + 30;
16+
}
17+
18+
int data_;
19+
};
20+
}
21+
22+
int taint_source() {return 1;}
23+
24+
void df_test() {
25+
int i;
26+
Data data;
27+
28+
data.data_ = taint_source();
29+
i = data.process1<void>();
30+
i = data.process2<void>(data.data_);
31+
i = data.process3();
32+
}

cpp/ql/test/library-tests/ir/test/PrintAST.expected

+49,780
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @kind graph
3+
*/
4+
5+
private import cpp
6+
private import semmle.code.cpp.PrintAST
7+
private import PrintConfig
8+
9+
private class PrintConfig extends PrintAstConfiguration {
10+
override predicate shouldPrintDeclaration(Declaration decl) { shouldDumpDeclaration(decl) }
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
private import cpp
2+
3+
/**
4+
* Holds if the specified location is in standard headers.
5+
*/
6+
predicate locationIsInStandardHeaders(Location loc) {
7+
loc.getFile().getAbsolutePath().regexpMatch(".*/include/[^/]+")
8+
}
9+
10+
/**
11+
* Holds if the AST or IR for the specified declaration should be printed in the test output.
12+
*
13+
* This predicate excludes declarations defined in standard headers.
14+
*/
15+
predicate shouldDumpDeclaration(Declaration decl) {
16+
not locationIsInStandardHeaders(decl.getLocation()) and
17+
(
18+
decl instanceof Function
19+
or
20+
decl.(GlobalOrNamespaceVariable).hasInitializer()
21+
or
22+
decl.(StaticLocalVariable).hasInitializer()
23+
)
24+
}

cpp/ql/test/test/test.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
char *getenv(const char *name);
2+
int printf(const char * format, ...);
3+
int atoi(const char *str);
4+
5+
void bad1(){
6+
int factor = atoi(getenv("BRANCHING_FACTOR"));
7+
int i;
8+
for(i = 0; i<factor; i++){
9+
printf("sfasdfad");
10+
}
11+
}
12+
13+
14+
void bad2(){
15+
int factor = atoi(getenv("BRANCHING_FACTOR"));
16+
int i = 0;
17+
while (i < factor)
18+
{
19+
printf("sfasdfad");
20+
i++;
21+
}
22+
}
23+
24+
int main(){
25+
26+
}

cpp/ql/test/test/test.expected

Whitespace-only changes.

cpp/ql/test/test/test.ql

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
3+
/**
4+
* @name Untrusted input for a condition
5+
* @description Using untrusted inputs in a statement that makes a
6+
* security decision makes code vulnerable to
7+
* attack.
8+
* @kind path-problem
9+
* @problem.severity warning
10+
* @security-severity 7.5
11+
* @precision medium
12+
* @id cpp/tainted-loop-check
13+
* @tags security
14+
* external/cwe/cwe-606
15+
*/
16+
17+
import cpp
18+
import semmle.code.cpp.security.Security
19+
import semmle.code.cpp.security.FlowSources
20+
import semmle.code.cpp.ir.dataflow.TaintTracking
21+
import semmle.code.cpp.ir.IR
22+
import Flow::PathGraph
23+
24+
predicate sensitiveCondition(Expr condition) {
25+
exists(ForStmt forstmt |
26+
forstmt.getCondition().getAChild*() = condition
27+
)
28+
}
29+
30+
31+
predicate isSource(FlowSource source, string sourceType) { sourceType = source.getSourceType() }
32+
33+
module Config implements DataFlow::ConfigSig {
34+
predicate isSource(DataFlow::Node node) { isSource(node, _) }
35+
36+
predicate isSink(DataFlow::Node node) {
37+
sensitiveCondition(node.asExpr())
38+
}
39+
40+
}
41+
42+
module Flow = TaintTracking::Global<Config>;
43+
44+
45+
from
46+
string sourceType, DataFlow::Node source, DataFlow::Node sink,
47+
Flow::PathNode sourceNode, Flow::PathNode sinkNode
48+
where
49+
source = sourceNode.getNode() and
50+
sink = sinkNode.getNode() and
51+
isSource(source, sourceType) and
52+
sensitiveCondition(sink.asExpr()) and
53+
Flow::flowPath(sourceNode, sinkNode)
54+
select sink, sourceNode, sinkNode, "Taint data to loop condition"

0 commit comments

Comments
 (0)