Skip to content

Commit 7ef96e3

Browse files
committed
C++: Add taint-inheriting reads from the Winhttp structs.
1 parent 5531ef9 commit 7ef96e3

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ private import implementations.CAtlFile
5757
private import implementations.CAtlFileMapping
5858
private import implementations.CAtlTemporaryFile
5959
private import implementations.CRegKey
60+
private import implementations.WinHttp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
private import cpp
2+
private import semmle.code.cpp.ir.dataflow.FlowSteps
3+
private import semmle.code.cpp.dataflow.new.DataFlow
4+
5+
/** The `WINHTTP_HEADER_NAME` classes from `winhttp.h`. */
6+
class WinHttpHeaderName extends Class {
7+
WinHttpHeaderName() { this.hasGlobalName("_WINHTTP_HEADER_NAME") }
8+
}
9+
10+
/** The `WINHTTP_EXTENDED_HEADER` classes from `winhttp.h`. */
11+
class WinHttpExtendedHeader extends Class {
12+
WinHttpExtendedHeader() { this.hasGlobalName("_WINHTTP_EXTENDED_HEADER") }
13+
}
14+
15+
private class WinHttpHeaderNameInheritingContent extends TaintInheritingContent,
16+
DataFlow::FieldContent
17+
{
18+
WinHttpHeaderNameInheritingContent() {
19+
this.getIndirectionIndex() = 2 and
20+
(
21+
this.getAField().getDeclaringType() instanceof WinHttpHeaderName
22+
or
23+
// The extended header looks like:
24+
// struct WINHTTP_EXTENDED_HEADER {
25+
// union { [...] };
26+
// union { [...] };
27+
// };
28+
// So the first declaring type is the anonymous unions, and the declaring
29+
// type of those anonymous unions is the `WINHTTP_EXTENDED_HEADER` struct.
30+
this.getAField().getDeclaringType().getDeclaringType() instanceof WinHttpExtendedHeader
31+
)
32+
}
33+
}
34+
35+
class WinHttpUrlComponents extends Class {
36+
WinHttpUrlComponents() { this.hasGlobalName("_WINHTTP_URL_COMPONENTS") }
37+
}
38+
39+
private class WinHttpUrlComponentsInheritingContent extends TaintInheritingContent,
40+
DataFlow::FieldContent
41+
{
42+
WinHttpUrlComponentsInheritingContent() {
43+
exists(Field f | f = this.getField() and f.getDeclaringType() instanceof WinHttpUrlComponents |
44+
if f.getType().getUnspecifiedType() instanceof PointerType
45+
then this.getIndirectionIndex() = 2
46+
else this.getIndirectionIndex() = 1
47+
)
48+
}
49+
}

0 commit comments

Comments
 (0)