Add support for indirect null-pointer dereferences.

main
Kevin Backhouse 2 years ago committed by Rosen Penev
parent 79ffedcbb5
commit a89c02f927

@ -24,15 +24,42 @@ class PrintFunction extends Function {
} }
} }
from PrintFunction f, Parameter p, Call call, Expr qualifier predicate metadataDeref(Expr metadata) {
where exists(Call call | call.getQualifier() = metadata)
p = f.getParameter(2) and or
qualifier = p.getAnAccess() and exists(FunctionCall call, int argIndex, Function f |
call.getQualifier() = qualifier and call.getArgument(argIndex) = metadata and
// Don't complain if the access is protected by a null check. f = call.getTarget() and
not exists(GuardCondition nonNullCheck, BasicBlock block, boolean branch | metadataDeref(f.getParameter(argIndex).getAnAccess())
validCheckExpr(nonNullCheck, p) and
nonNullCheck.controls(block, branch) and
block.contains(call)
) )
select qualifier, "Print functions need to check that the metadata isn't null." }
predicate unsafePointerParam(Function f, int paramIndex, Expr use) {
exists(Parameter p |
p = f.getParameter(paramIndex) and
use = p.getAnAccess() and
unsafePointerExpr(use) and
not exists(GuardCondition nonNullCheck, BasicBlock block, boolean branch |
validCheckExpr(nonNullCheck, p) and
nonNullCheck.controls(block, branch) and
block.contains(use)
)
)
}
predicate unsafePointerExpr(Expr e) {
exists(Call call |
call.getQualifier() = e and
e.getType().getUnspecifiedType() instanceof PointerType
)
or
exists(FunctionCall call, int argIndex, Function f |
call.getArgument(argIndex) = e and
f = call.getTarget() and
unsafePointerParam(f, argIndex, _)
)
}
from PrintFunction printfcn, Parameter p, Expr metadata
where unsafePointerParam(printfcn, 2, metadata)
select metadata, "Print functions need to check that the metadata isn't null."

Loading…
Cancel
Save