File tree Expand file tree Collapse file tree
CodeQL_Queries/cpp/Facebook_Fizz_CVE-2019-3560 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,27 +22,30 @@ class EndianConvert extends Function {
2222 }
2323}
2424
25+ /**
26+ * Holds if `i` is an endianness conversion.
27+ * (A telltale sign of network data.)
28+ */
29+ predicate isNetworkData ( Instruction i ) {
30+ i .( CallInstruction ) .getCallTarget ( ) .( FunctionInstruction ) .getFunctionSymbol ( ) instanceof
31+ EndianConvert
32+ }
33+
34+ /** Holds if `i` is a narrowing conversion. */
35+ predicate isNarrowingConversion ( ConvertInstruction i ) {
36+ i .getResultSize ( ) < i .getUnary ( ) .getResultSize ( )
37+ }
38+
2539class Cfg extends TaintTracking:: Configuration {
2640 Cfg ( ) { this = "FizzOverflowIR" }
2741
28- /** Holds if `source` is a call to `Endian::big()`. */
29- override predicate isSource ( DataFlow:: Node source ) {
30- source
31- .asInstruction ( )
32- .( CallInstruction )
33- .getCallTarget ( )
34- .( FunctionInstruction )
35- .getFunctionSymbol ( ) instanceof EndianConvert
36- }
42+ /**
43+ * Holds if `source` is network data.
44+ */
45+ override predicate isSource ( DataFlow:: Node source ) { isNetworkData ( source .asInstruction ( ) ) }
3746
3847 /** Holds if `sink` is a narrowing conversion. */
39- override predicate isSink ( DataFlow:: Node sink ) {
40- sink .asInstruction ( ) .getResultSize ( ) < sink
41- .asInstruction ( )
42- .( ConvertInstruction )
43- .getUnary ( )
44- .getResultSize ( )
45- }
48+ override predicate isSink ( DataFlow:: Node sink ) { isNarrowingConversion ( sink .asInstruction ( ) ) }
4649}
4750
4851from
Original file line number Diff line number Diff line change 1+ /**
2+ * @name Narrowing conversions
3+ * @description Find all narrowing conversions from a larger integer type,
4+ * such as uint32_t, to a smaller integer type, such as uint8_t.
5+ * @kind problem
6+ */
7+
8+ import cpp
9+ import semmle.code.cpp.ir.IR
10+
11+ /** Holds if `i` is a narrowing conversion. */
12+ predicate isNarrowingConversion ( ConvertInstruction i ) {
13+ i .getResultSize ( ) < i .getUnary ( ) .getResultSize ( )
14+ }
15+
16+ from ConvertInstruction conv , Type inputType , Type outputType
17+ where
18+ isNarrowingConversion ( conv ) and
19+ inputType = conv .getUnary ( ) .getResultType ( ) and
20+ outputType = conv .getResultType ( )
21+ select conv , "Narrowing conversion from " + inputType + " to " + outputType + "."
You can’t perform that action at this time.
0 commit comments