|
| 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