Skip to content

Commit ea26e21

Browse files
author
Max Schaefer
committed
Extend negative characteristics for exceptions to source models.
1 parent 06ba5ea commit ea26e21

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,22 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Nei
436436
}
437437

438438
/**
439-
* A negative characteristic that indicates that an endpoint is an argument to an exception, which is not a sink.
439+
* A negative characteristic that indicates that parameters of an exception method or constructor should not be considered sinks,
440+
* and its return value should not be considered a source.
440441
*/
441-
private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkCharacteristic {
442+
private class ExceptionCharacteristic extends CharacteristicsImpl::NeitherSourceNorSinkCharacteristic {
442443
ExceptionCharacteristic() { this = "exception" }
443444

444445
override predicate appliesToEndpoint(Endpoint e) {
445-
e.(CallArgument).getCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable
446+
e.getCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable and
447+
(
448+
e.getExtensibleType() = "sinkModel" and
449+
not ApplicationCandidatesImpl::isSink(e, _, _)
450+
or
451+
e.getExtensibleType() = "sourceModel" and
452+
not ApplicationCandidatesImpl::isSource(e, _, _) and
453+
e.getMaDOutput() = "ReturnValue"
454+
)
446455
}
447456
}
448457

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,26 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Nei
377377
}
378378

379379
/**
380-
* A negative characteristic that indicates that an endpoint is an argument to an exception, which is not a sink.
380+
* A negative characteristic that indicates that parameters of an exception method or constructor should not be considered sinks,
381+
* and its return value should not be considered a source.
381382
*/
382-
private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkCharacteristic {
383+
private class ExceptionCharacteristic extends CharacteristicsImpl::NeitherSourceNorSinkCharacteristic {
383384
ExceptionCharacteristic() { this = "exception" }
384385

385386
override predicate appliesToEndpoint(Endpoint e) {
386-
e.getEnclosingCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable
387+
e.getEnclosingCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable and
388+
(
389+
e.getExtensibleType() = "sinkModel" and
390+
not FrameworkCandidatesImpl::isSink(e, _, _)
391+
or
392+
e.getExtensibleType() = "sourceModel" and
393+
not FrameworkCandidatesImpl::isSource(e, _, _) and
394+
e.getMaDOutput() = "ReturnValue"
395+
)
387396
}
388397
}
389398

399+
390400
/**
391401
* A characteristic that limits candidates to parameters of methods that are recognized as `ModelApi`, iow., APIs that
392402
* are considered worth modeling.

0 commit comments

Comments
 (0)