Skip to content

Commit b009886

Browse files
committed
Java: Add TypeObjectInputStream
1 parent a74d423 commit b009886

File tree

6 files changed

+26
-54
lines changed

6 files changed

+26
-54
lines changed

java/ql/lib/semmle/code/java/JDK.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ class TypeObjectOutputStream extends RefType {
156156
TypeObjectOutputStream() { hasQualifiedName("java.io", "ObjectOutputStream") }
157157
}
158158

159+
/** The type `java.io.ObjectInputStream`. */
160+
class TypeObjectInputStream extends RefType {
161+
TypeObjectInputStream() { hasQualifiedName("java.io", "ObjectInputStream") }
162+
}
163+
159164
/** The class `java.nio.file.Paths`. */
160165
class TypePaths extends Class {
161166
TypePaths() { this.hasQualifiedName("java.nio.file", "Paths") }
@@ -275,7 +280,7 @@ class WriteObjectMethod extends Method {
275280
*/
276281
class ReadObjectMethod extends Method {
277282
ReadObjectMethod() {
278-
this.getDeclaringType().hasQualifiedName("java.io", "ObjectInputStream") and
283+
this.getDeclaringType() instanceof TypeObjectInputStream and
279284
(
280285
this.hasName("readObject") or
281286
this.hasName("readObjectOverride") or

java/ql/lib/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private predicate taintPreservingQualifierToMethod(Method m) {
269269
m.getName() = "toString"
270270
)
271271
or
272-
m.getDeclaringType().hasQualifiedName("java.io", "ObjectInputStream") and
272+
m.getDeclaringType() instanceof TypeObjectInputStream and
273273
m.getName().matches("read%")
274274
or
275275
m instanceof GetterMethod and

java/ql/lib/semmle/code/java/frameworks/javaee/ejb/EJBRestrictions.qll

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ class RuntimeExitOrHaltMethod extends Method {
299299
(this.hasName("exit") or this.hasName("halt")) and
300300
this.getNumberOfParameters() = 1 and
301301
this.getParameter(0).getType().(PrimitiveType).hasName("int") and
302-
this.getDeclaringType()
303-
.getASupertype*()
304-
.getSourceDeclaration()
305-
.hasQualifiedName("java.lang", "Runtime")
302+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeRuntime
306303
}
307304
}
308305

@@ -315,10 +312,7 @@ class RuntimeAddOrRemoveShutdownHookMethod extends Method {
315312
(this.hasName("addShutdownHook") or this.hasName("removeShutdownHook")) and
316313
this.getNumberOfParameters() = 1 and
317314
this.getParameter(0).getType().(RefType).hasQualifiedName("java.lang", "Thread") and
318-
this.getDeclaringType()
319-
.getASupertype*()
320-
.getSourceDeclaration()
321-
.hasQualifiedName("java.lang", "Runtime")
315+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeRuntime
322316
}
323317
}
324318

@@ -414,33 +408,29 @@ class ForbiddenSerializationMethod extends Method {
414408

415409
/**
416410
* A method named `enableReplaceObject` declared in
417-
* the class `java.io.ObjectInputStream` or a subclass thereof.
411+
* the class `java.io.ObjectOutputStream` or a subclass thereof.
418412
*/
419413
class EnableReplaceObjectMethod extends Method {
420414
EnableReplaceObjectMethod() {
421415
this.hasName("enableReplaceObject") and
422416
this.getNumberOfParameters() = 1 and
423417
this.getParameter(0).getType().(PrimitiveType).hasName("boolean") and
424-
this.getDeclaringType()
425-
.getASupertype*()
426-
.getSourceDeclaration()
427-
.hasQualifiedName("java.io", "ObjectOutputStream")
418+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof
419+
TypeObjectOutputStream
428420
}
429421
}
430422

431423
/**
432424
* A method named `replaceObject` declared in
433-
* the class `java.io.ObjectInputStream` or a subclass thereof.
425+
* the class `java.io.ObjectOutputStream` or a subclass thereof.
434426
*/
435427
class ReplaceObjectMethod extends Method {
436428
ReplaceObjectMethod() {
437429
this.hasName("replaceObject") and
438430
this.getNumberOfParameters() = 1 and
439431
this.getParameter(0).getType() instanceof TypeObject and
440-
this.getDeclaringType()
441-
.getASupertype*()
442-
.getSourceDeclaration()
443-
.hasQualifiedName("java.io", "ObjectOutputStream")
432+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof
433+
TypeObjectOutputStream
444434
}
445435
}
446436

@@ -453,10 +443,7 @@ class EnableResolveObjectMethod extends Method {
453443
this.hasName("enableResolveObject") and
454444
this.getNumberOfParameters() = 1 and
455445
this.getParameter(0).getType().(PrimitiveType).hasName("boolean") and
456-
this.getDeclaringType()
457-
.getASupertype*()
458-
.getSourceDeclaration()
459-
.hasQualifiedName("java.io", "ObjectInputStream")
446+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeObjectInputStream
460447
}
461448
}
462449

@@ -469,10 +456,7 @@ class ResolveObjectMethod extends Method {
469456
this.hasName("resolveObject") and
470457
this.getNumberOfParameters() = 1 and
471458
this.getParameter(0).getType() instanceof TypeObject and
472-
this.getDeclaringType()
473-
.getASupertype*()
474-
.getSourceDeclaration()
475-
.hasQualifiedName("java.io", "ObjectInputStream")
459+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeObjectInputStream
476460
}
477461
}
478462

@@ -485,10 +469,7 @@ class ResolveClassMethod extends Method {
485469
this.hasName("resolveClass") and
486470
this.getNumberOfParameters() = 1 and
487471
this.getParameter(0).getType().(RefType).hasQualifiedName("java.io", "ObjectStreamClass") and
488-
this.getDeclaringType()
489-
.getASupertype*()
490-
.getSourceDeclaration()
491-
.hasQualifiedName("java.io", "ObjectInputStream")
472+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeObjectInputStream
492473
}
493474
}
494475

@@ -500,16 +481,8 @@ class ResolveProxyClassMethod extends Method {
500481
ResolveProxyClassMethod() {
501482
this.hasName("resolveProxyClass") and
502483
this.getNumberOfParameters() = 1 and
503-
this.getParameter(0)
504-
.getType()
505-
.(Array)
506-
.getComponentType()
507-
.(RefType)
508-
.hasQualifiedName("java.lang", "String") and
509-
this.getDeclaringType()
510-
.getASupertype*()
511-
.getSourceDeclaration()
512-
.hasQualifiedName("java.io", "ObjectInputStream")
484+
this.getParameter(0).getType().(Array).getComponentType() instanceof TypeString and
485+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeObjectInputStream
513486
}
514487
}
515488

@@ -598,16 +571,13 @@ class SystemOrRuntimeLoadLibraryMethod extends Method {
598571
SystemOrRuntimeLoadLibraryMethod() {
599572
(this.hasName("load") or this.hasName("loadLibrary")) and
600573
this.getNumberOfParameters() = 1 and
601-
this.getParameter(0).getType().(RefType).hasQualifiedName("java.lang", "String") and
574+
this.getParameter(0).getType() instanceof TypeString and
602575
(
603576
this.getDeclaringType()
604577
.getASupertype*()
605578
.getSourceDeclaration()
606579
.hasQualifiedName("java.lang", "System") or
607-
this.getDeclaringType()
608-
.getASupertype*()
609-
.getSourceDeclaration()
610-
.hasQualifiedName("java.lang", "Runtime")
580+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeRuntime
611581
)
612582
}
613583
}
@@ -619,9 +589,6 @@ class SystemOrRuntimeLoadLibraryMethod extends Method {
619589
class RuntimeExecMethod extends Method {
620590
RuntimeExecMethod() {
621591
this.hasName("exec") and
622-
this.getDeclaringType()
623-
.getASupertype*()
624-
.getSourceDeclaration()
625-
.hasQualifiedName("java.lang", "Runtime")
592+
this.getDeclaringType().getASupertype*().getSourceDeclaration() instanceof TypeRuntime
626593
}
627594
}

java/ql/lib/semmle/code/java/security/UnsafeDeserializationQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private import semmle.code.java.Reflection
2222

2323
private class ObjectInputStreamReadObjectMethod extends Method {
2424
ObjectInputStreamReadObjectMethod() {
25-
this.getDeclaringType().getASourceSupertype*().hasQualifiedName("java.io", "ObjectInputStream") and
25+
this.getDeclaringType().getASourceSupertype*() instanceof TypeObjectInputStream and
2626
(this.hasName("readObject") or this.hasName("readUnshared"))
2727
}
2828
}

java/ql/src/Likely Bugs/Concurrency/SynchWriteObject.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
m.getDeclaringType().getASupertype*() instanceof TypeSerializable and
2121
m.hasName("writeObject") and
2222
m.getNumberOfParameters() = 1 and
23-
m.getAParamType().(Class).hasQualifiedName("java.io", "ObjectOutputStream") and
23+
m.getAParamType() instanceof TypeObjectOutputStream and
2424
m.isSynchronized() and
2525
not exists(Method s |
2626
m.getDeclaringType().inherits(s) and

java/ql/src/experimental/Security/CWE/CWE-502/UnsafeDeserializationRmi.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private predicate hasVulnerableMethod(RefType type) {
3939
|
4040
not parameterType instanceof PrimitiveType and
4141
not parameterType instanceof TypeString and
42-
not parameterType.(RefType).hasQualifiedName("java.io", "ObjectInputStream")
42+
not parameterType instanceof TypeObjectInputStream
4343
)
4444
}
4545

0 commit comments

Comments
 (0)