Skip to content

Commit 636d5e3

Browse files
authored
Merge pull request github#11652 from erik-krogh/static-useInstanceOf
Java/C#/GO: Use instanceof in more places
2 parents 0ebfee8 + 873d355 commit 636d5e3

File tree

60 files changed

+116
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+116
-287
lines changed

csharp/ql/lib/semmle/code/csharp/commons/Assertions.qll

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -368,40 +368,32 @@ private Stmt getAnAssertingStmt(Assertion a) {
368368
}
369369

370370
/** A method that forwards to a Boolean assertion method. */
371-
class ForwarderBooleanAssertMethod extends BooleanAssertMethod {
372-
private ForwarderAssertMethod forwarder;
371+
class ForwarderBooleanAssertMethod extends BooleanAssertMethod instanceof ForwarderAssertMethod {
373372
private BooleanAssertMethod underlying;
374373

375-
ForwarderBooleanAssertMethod() {
376-
forwarder = this and
377-
underlying = forwarder.getUnderlyingAssertMethod()
378-
}
374+
ForwarderBooleanAssertMethod() { underlying = super.getUnderlyingAssertMethod() }
379375

380376
override int getAnAssertionIndex(boolean b) {
381-
forwarder.getAForwarderAssertionIndex(result) = underlying.getAnAssertionIndex(b)
377+
super.getAForwarderAssertionIndex(result) = underlying.getAnAssertionIndex(b)
382378
}
383379

384380
override AssertionFailure getAssertionFailure(int i) {
385-
result = underlying.getAssertionFailure(forwarder.getAForwarderAssertionIndex(i))
381+
result = underlying.getAssertionFailure(super.getAForwarderAssertionIndex(i))
386382
}
387383
}
388384

389385
/** A method that forwards to a nullness assertion method. */
390-
class ForwarderNullnessAssertMethod extends NullnessAssertMethod {
391-
private ForwarderAssertMethod forwarder;
386+
class ForwarderNullnessAssertMethod extends NullnessAssertMethod instanceof ForwarderAssertMethod {
392387
private NullnessAssertMethod underlying;
393388

394-
ForwarderNullnessAssertMethod() {
395-
forwarder = this and
396-
underlying = forwarder.getUnderlyingAssertMethod()
397-
}
389+
ForwarderNullnessAssertMethod() { underlying = super.getUnderlyingAssertMethod() }
398390

399391
override int getAnAssertionIndex(boolean b) {
400-
forwarder.getAForwarderAssertionIndex(result) = underlying.getAnAssertionIndex(b)
392+
super.getAForwarderAssertionIndex(result) = underlying.getAnAssertionIndex(b)
401393
}
402394

403395
override AssertionFailure getAssertionFailure(int i) {
404-
result = underlying.getAssertionFailure(forwarder.getAForwarderAssertionIndex(i))
396+
result = underlying.getAssertionFailure(super.getAForwarderAssertionIndex(i))
405397
}
406398
}
407399

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ContentDataFlow.qll

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,14 @@ module ContentDataFlow {
222222
)
223223
}
224224

225-
private class ConfigurationAdapter extends DF::Configuration {
226-
private Configuration c;
227-
228-
ConfigurationAdapter() { this = c }
229-
225+
private class ConfigurationAdapter extends DF::Configuration instanceof Configuration {
230226
final override predicate isSource(Node source, DF::FlowState state) {
231-
c.isSource(source) and
227+
Configuration.super.isSource(source) and
232228
state.(InitState).decode(true)
233229
}
234230

235231
final override predicate isSink(Node sink, DF::FlowState state) {
236-
c.isSink(sink) and
232+
Configuration.super.isSink(sink) and
237233
(
238234
state instanceof InitState or
239235
state instanceof StoreState or
@@ -249,9 +245,9 @@ module ContentDataFlow {
249245
additionalStep(node1, state1, node2, state2, this)
250246
}
251247

252-
final override predicate isBarrier(Node node) { c.isBarrier(node) }
248+
final override predicate isBarrier(Node node) { Configuration.super.isBarrier(node) }
253249

254-
final override FlowFeature getAFeature() { result = c.getAFeature() }
250+
final override FlowFeature getAFeature() { result = Configuration.super.getAFeature() }
255251

256252
// needed to record reads/stores inside summarized callables
257253
final override predicate includeHiddenNodes() { any() }

csharp/ql/lib/semmle/code/csharp/frameworks/System.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ class SystemNullReferenceExceptionClass extends SystemClass {
257257
}
258258

259259
/** The `System.Object` class. */
260-
class SystemObjectClass extends SystemClass {
261-
SystemObjectClass() { this instanceof ObjectType }
262-
260+
class SystemObjectClass extends SystemClass instanceof ObjectType {
263261
/** Gets the `Equals(object)` method. */
264262
Method getEqualsMethod() {
265263
result.getDeclaringType() = this and

csharp/ql/lib/semmle/code/csharp/security/dataflow/CleartextStorageQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,4 @@ class ProtectSanitizer extends Sanitizer {
5656
/**
5757
* An external location sink.
5858
*/
59-
class ExternalSink extends Sink {
60-
ExternalSink() { this instanceof ExternalLocationSink }
61-
}
59+
class ExternalSink extends Sink instanceof ExternalLocationSink { }

csharp/ql/lib/semmle/code/csharp/security/dataflow/CodeInjectionQuery.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
3838
}
3939

4040
/** A source of remote user input. */
41-
class RemoteSource extends Source {
42-
RemoteSource() { this instanceof RemoteFlowSource }
43-
}
41+
class RemoteSource extends Source instanceof RemoteFlowSource { }
4442

4543
/** A source of local user input. */
46-
class LocalSource extends Source {
47-
LocalSource() { this instanceof LocalFlowSource }
48-
}
44+
class LocalSource extends Source instanceof LocalFlowSource { }
4945

5046
private class SimpleTypeSanitizer extends Sanitizer, SimpleTypeSanitizedExpr { }
5147

csharp/ql/lib/semmle/code/csharp/security/dataflow/CommandInjectionQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
3636
}
3737

3838
/** A source of remote user input. */
39-
class RemoteSource extends Source {
40-
RemoteSource() { this instanceof RemoteFlowSource }
41-
}
39+
class RemoteSource extends Source instanceof RemoteFlowSource { }
4240

4341
/**
4442
* A sink in `System.Diagnostic.Process` or its related classes.

csharp/ql/lib/semmle/code/csharp/security/dataflow/ConditionalBypassQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class Configuration extends TaintTracking::Configuration {
4343
}
4444

4545
/** A source of remote user input. */
46-
class RemoteSource extends Source {
47-
RemoteSource() { this instanceof RemoteFlowSource }
48-
}
46+
class RemoteSource extends Source instanceof RemoteFlowSource { }
4947

5048
/** The result of a reverse dns may be user-controlled. */
5149
class ReverseDnsSource extends Source {

csharp/ql/lib/semmle/code/csharp/security/dataflow/ExposureOfPrivateInformationQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@ private class PrivateDataSource extends Source {
3939
PrivateDataSource() { this.getExpr() instanceof PrivateDataExpr }
4040
}
4141

42-
private class ExternalLocation extends Sink {
43-
ExternalLocation() { this instanceof ExternalLocationSink }
44-
}
42+
private class ExternalLocation extends Sink instanceof ExternalLocationSink { }

csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ abstract class SafeExternalApiCallable extends Callable { }
1717
/** DEPRECATED: Alias for SafeExternalApiCallable */
1818
deprecated class SafeExternalAPICallable = SafeExternalApiCallable;
1919

20-
private class SummarizedCallableSafe extends SafeExternalApiCallable {
21-
SummarizedCallableSafe() { this instanceof SummarizedCallable }
20+
private class SummarizedCallableSafe extends SafeExternalApiCallable instanceof SummarizedCallable {
2221
}
2322

2423
/** The default set of "safe" external APIs. */

csharp/ql/lib/semmle/code/csharp/security/dataflow/LDAPInjectionQuery.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class TaintTrackingConfiguration extends TaintTracking::Configuration {
3838
}
3939

4040
/** A source of remote user input. */
41-
class RemoteSource extends Source {
42-
RemoteSource() { this instanceof RemoteFlowSource }
43-
}
41+
class RemoteSource extends Source instanceof RemoteFlowSource { }
4442

4543
/**
4644
* An argument that sets the `Path` property of a `DirectoryEntry` object that is a sink for LDAP

0 commit comments

Comments
 (0)