Skip to content

Commit 063bff0

Browse files
committed
C++: Add checks for build mode in various queries
Adds a check for the absence of build-mode-none in cpp/wrong-type-format-argument cpp/comparison-with-wider-type cpp/integer-multiplication-cast-to-long cpp/implicit-function-declaration cpp/suspicious-add-sizeof
1 parent 4093afb commit 063bff0

File tree

5 files changed

+5
-0
lines changed

5 files changed

+5
-0
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ predicate overflows(MulExpr me, Type t) {
179179

180180
from MulExpr me, Type t1, Type t2
181181
where
182+
not any(Compilation c).buildModeNone() and
182183
t1 = me.getType().getUnderlyingType() and
183184
t2 = me.getConversion().getType().getUnderlyingType() and
184185
t1.getSize() < t2.getSize() and

cpp/ql/src/Likely Bugs/Format/WrongTypeFormatArguments.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ int sizeof_IntType() { exists(IntType it | result = it.getSize()) }
154154

155155
from FormattingFunctionCall ffc, int n, Expr arg, Type expected, Type actual
156156
where
157+
not any(Compilation c).buildModeNone() and
157158
(
158159
formattingFunctionCallExpectedType(ffc, n, expected) and
159160
formattingFunctionCallActualType(ffc, n, arg, actual) and

cpp/ql/src/Likely Bugs/Underspecified Functions/ImplicitFunctionDeclaration.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ predicate isCompiledAsC(File f) {
3838

3939
from FunctionDeclarationEntry fdeIm, FunctionCall fc
4040
where
41+
not any(Compilation c).buildModeNone() and
4142
isCompiledAsC(fdeIm.getFile()) and
4243
not isFromMacroDefinition(fc) and
4344
fdeIm.isImplicit() and

cpp/ql/src/Security/CWE/CWE-190/ComparisonWithWiderType.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int getComparisonSizeAdjustment(Expr e) {
5151

5252
from Loop l, RelationalOperation rel, VariableAccess small, Expr large
5353
where
54+
not any(Compilation c).buildModeNone() and
5455
small = rel.getLesserOperand() and
5556
large = rel.getGreaterOperand() and
5657
rel = l.getCondition().getAChild*() and

cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private predicate isCharSzPtrExpr(Expr e) {
2424

2525
from Expr sizeofExpr, Expr e
2626
where
27+
not any(Compilation c).buildModeNone() and
2728
// If we see an addWithSizeof then we expect the type of
2829
// the pointer expression to be `char*` or `void*`. Otherwise it
2930
// is probably a mistake.

0 commit comments

Comments
 (0)