Skip to content

Commit 4db2191

Browse files
author
Nico Waisman
authored
Merge pull request #11 from kevinbackhouse/FizzDemo
Fizz demo
2 parents 2500cfb + e4ab7bb commit 4db2191

2 files changed

Lines changed: 40 additions & 16 deletions

File tree

CodeQL_Queries/cpp/Facebook_Fizz_CVE-2019-3560/FizzOverflow.ql

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff 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+
2539
class 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

4851
from
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 + "."

0 commit comments

Comments
 (0)