Skip to content

Commit 01a06d1

Browse files
committed
Add filter and format the query
1 parent cf40d0a commit 01a06d1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-787/UnsignedToSignedPointerArith.ql

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import semmle.code.cpp.security.Overflow
1515

1616
from FunctionCall call, Function f, Parameter p, DataFlow::Node sink, PointerArithmeticOperation pao
1717
where
18-
f = call.getTarget() and
19-
p = f.getAParameter() and
20-
p.getUnspecifiedType().(IntegralType).isSigned() and
21-
call.getArgument(p.getIndex()).getUnspecifiedType().(IntegralType).isUnsigned() and
22-
pao.getAnOperand() = sink.asExpr() and
23-
not exists(Operation a | guardedLesser(a, sink.asExpr())) and
24-
not exists(Operation b | guardedGreater(b, call.getArgument(p.getIndex()))) and
25-
not call.getArgument(p.getIndex()).isConstant() and
26-
DataFlow::localFlow(DataFlow::parameterNode(p), sink)
27-
select call, "This call: $@ passes an unsigned int to a function that requires a signed int: $@. And then used in pointer arithmetic: $@", call, call.toString(), f, f.toString(), sink, sink.toString()
18+
f = call.getTarget() and
19+
p = f.getAParameter() and
20+
p.getUnspecifiedType().(IntegralType).isSigned() and
21+
call.getArgument(p.getIndex()).getUnspecifiedType().(IntegralType).isUnsigned() and
22+
pao.getAnOperand() = sink.asExpr() and
23+
not exists(Operation a | guardedLesser(a, sink.asExpr())) and
24+
not exists(Operation b | guardedGreater(b, call.getArgument(p.getIndex()))) and
25+
not call.getArgument(p.getIndex()).isConstant() and
26+
DataFlow::localFlow(DataFlow::parameterNode(p), sink) and
27+
p.getUnspecifiedType().getSize() < 8
28+
select call,
29+
"This call: $@ passes an unsigned int to a function that requires a signed int: $@. And then used in pointer arithmetic: $@",
30+
call, call.toString(), f, f.toString(), sink, sink.toString()

0 commit comments

Comments
 (0)