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

Skip to content

Commit 74eae4a

Browse files
committed
C++: Add a MaD model for 'CAtlFile' and mark reads as local flow sources.
1 parent dee47f2 commit 74eae4a

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

cpp/ql/lib/ext/CAtlFile.model.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: summaryModel
5+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
6+
- ["", "CAtlFile", True, "CAtlFile", "(CAtlFile &)", "", "Argument[*0]", "Argument[-1]", "value", "manual"]
7+
- ["", "CAtlFile", True, "CAtlFile", "(HANDLE)", "", "Argument[0]", "Argument[-1]", "taint", "manual"]
8+
- ["", "CAtlFile", True, "Create", "", "", "Argument[*0]", "Argument[-1]", "taint", "manual"]
9+
- ["", "CAtlFile", True, "Read", "", "", "Argument[-1]", "Argument[*0]", "taint", "manual"]

cpp/ql/lib/semmle/code/cpp/models/Models.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ private import implementations.Win32CommandExecution
5353
private import implementations.CA2AEX
5454
private import implementations.CComBSTR
5555
private import implementations.CPathT
56+
private import implementations.CAtlFile
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import semmle.code.cpp.models.interfaces.FlowSource
2+
3+
/**
4+
* The `CAtlFile` class from Microsoft's Active Template Library.
5+
*/
6+
class CAtlFile extends Class {
7+
CAtlFile() { this.hasGlobalName("CAtlFile") }
8+
}
9+
10+
private class CAtlFileRead extends MemberFunction, LocalFlowSourceFunction {
11+
CAtlFileRead() { this.getClassAndName("Read") instanceof CAtlFile }
12+
13+
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
14+
output.isParameterDeref(0) and
15+
description = "string read by " + this.getName()
16+
}
17+
}

cpp/ql/test/library-tests/dataflow/source-sink-tests/atl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ struct CAtlFile : public CHandle {
133133
void test_CAtlFile() {
134134
CAtlFile catFile;
135135
char buffer[1024];
136-
catFile.Read(buffer, 1024); // $ MISSING: local_source
136+
catFile.Read(buffer, 1024); // $ local_source
137137
}

0 commit comments

Comments
 (0)