Skip to content

Commit f03520b

Browse files
committed
finalize
1 parent 1f2598e commit f03520b

4 files changed

Lines changed: 398 additions & 26 deletions

File tree

cpp/src/security/DecOverflowWhenComparing/DecOverflowWhenComparing.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ where
139139
)
140140
then cmp.getAFalseSuccessor().getASuccessor*() = varAccAfterOverflow
141141
else any()
142-
) and
143-
// skip vendor code
144-
not dec.getFile().getAbsolutePath().toLowerCase().matches(["%vendor%", "%third_party%"])
142+
)
143+
145144
select dec, "Unsigned decrementation in comparison ($@) - $@", cmp, cmp.toString(),
146145
varAccAfterOverflow, varAccAfterOverflow.toString()

cpp/src/security/InconsistentReturnValueHandling/InconsistentReturnValueHandling.ql

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ newtype TCmpClass =
3535
Targ()
3636
or
3737
Tarithm()
38+
or
39+
Tother()
3840

3941
class CmpClass extends TCmpClass {
4042
string toString() {
@@ -53,6 +55,8 @@ class CmpClass extends TCmpClass {
5355
this = Tarithm() and result = " arithmetic expression"
5456
or
5557
this = Targ() and result = "in a function"
58+
or
59+
this = Tother() and result = " other expression"
5660
}
5761
}
5862

@@ -127,19 +131,19 @@ TCmpClass operandCategory(Expr comparedVal) {
127131
)
128132
or
129133
(binaryComputation(comparedVal) and result = Tarithm())
134+
or
135+
(
136+
not numericArithmLiteral(comparedVal)
137+
and not (comparedVal instanceof Literal and comparedVal.getType() instanceof BoolType)
138+
and not (comparedVal.getType() instanceof NullPointerType or comparedVal instanceof NULL)
139+
and not comparedVal.getUnderlyingType() instanceof DerivedType
140+
and not comparedVal instanceof Call
141+
and not comparedVal instanceof SizeofOperator
142+
and not binaryComputation(comparedVal)
143+
and result = Tother()
144+
)
130145
}
131146

132-
// module RetValFlowConfig implements DataFlow::ConfigSig {
133-
// predicate isSource(DataFlow::Node source) {
134-
// source.asExpr() = any(Call f)
135-
// }
136-
137-
// predicate isSink(DataFlow::Node sink) {
138-
// exists(IfStmt ifs | ifs.getCondition().getAChild*() = sink.asExpr())
139-
// }
140-
// }
141-
// module RetValFlow = DataFlow::Global<RetValFlowConfig>;
142-
143147
/**
144148
* Given function's return value, find its first use in an IF statement
145149
* and assign proper TCmpClass category
@@ -156,7 +160,7 @@ predicate categorize(Function f, Call fc, TCmpClass comparedValCategory, IfStmt
156160
)
157161

158162
// exclude far-reaching flows, when the ret val is not checked but is actually used
159-
// in other words, find only the first use in an IF statement
163+
// in other words, find only the first use in an IF statement
160164
and not exists(IfStmt ifsPrev |
161165
ifsPrev != ifs
162166
and DataFlow::localFlow(
@@ -224,22 +228,11 @@ int mostCommonRetValType(Function f, TCmpClass mostCommonCategory) {
224228
)
225229
}
226230

227-
// uncomment for testing:
228-
// from Function f, Call fc, TCmpClass comparedValCategory, CmpClass x, IfStmt ifs
229-
// where
230-
// categorize(f, fc, comparedValCategory, ifs)
231-
// and x = comparedValCategory
232-
// // and f.getName() = "sshbuf_fromb"
233-
// select f, fc, x, ifs
234-
235-
236231
from Function f, int retValsTotalAmount,
237232
TCmpClass mostCommonCategory, CmpClass mostCommonCategoryClass, int categoryMax,
238233
TCmpClass buggyCategory, CmpClass buggyCategoryClass, Call buggyFc,
239234
IfStmt ifs
240235
where
241-
// not buggyFc.getLocation().getFile().toString().toLowerCase().regexpMatch(".*test.*") and
242-
243236
// we are interested only in defined (e.g., not libc) and used functions
244237
exists(Call fc | fc.getTarget() = f)
245238
and f.hasDefinition()

0 commit comments

Comments
 (0)