@@ -48,6 +48,65 @@ class SafeKryo extends DataFlow2::Configuration {
4848 ma .getMethod ( ) instanceof KryoReadObjectMethod
4949 )
5050 }
51+
52+ override predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
53+ stepKryoPoolBuilderFactoryArgToConstructor ( node1 , node2 ) or
54+ stepKryoPoolRunMethodAccessQualifierToFunctionalArgument ( node1 , node2 ) or
55+ stepKryoPoolBuilderChainMethod ( node1 , node2 ) or
56+ stepKryoPoolBorrowMethod ( node1 , node2 )
57+ }
58+
59+ /**
60+ * Holds when a functional expression is used to create a `KryoPool.Builder`.
61+ * Eg. `new KryoPool.Builder(() -> new Kryo())`
62+ */
63+ private predicate stepKryoPoolBuilderFactoryArgToConstructor (
64+ DataFlow:: Node node1 , DataFlow:: Node node2
65+ ) {
66+ exists ( ConstructorCall cc , FunctionalExpr fe |
67+ cc .getConstructedType ( ) instanceof KryoPoolBuilder and
68+ fe .asMethod ( ) .getBody ( ) .getAStmt ( ) .( ReturnStmt ) .getResult ( ) = node1 .asExpr ( ) and
69+ node2 .asExpr ( ) = cc and
70+ cc .getArgument ( 0 ) = fe
71+ )
72+ }
73+
74+ /**
75+ * Holds when a `KryoPool.run` is called to use a `Kryo` instance.
76+ * Eg. `pool.run(kryo -> ...)`
77+ */
78+ private predicate stepKryoPoolRunMethodAccessQualifierToFunctionalArgument (
79+ DataFlow:: Node node1 , DataFlow:: Node node2
80+ ) {
81+ exists ( MethodAccess ma |
82+ ma .getMethod ( ) instanceof KryoPoolRunMethod and
83+ node1 .asExpr ( ) = ma .getQualifier ( ) and
84+ ma .getArgument ( 0 ) .( FunctionalExpr ) .asMethod ( ) .getParameter ( 0 ) = node2 .asParameter ( )
85+ )
86+ }
87+
88+ /**
89+ * Holds when a `KryoPool.Builder` method is called fluently.
90+ */
91+ private predicate stepKryoPoolBuilderChainMethod ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
92+ exists ( MethodAccess ma |
93+ ma .getMethod ( ) instanceof KryoPoolBuilderMethod and
94+ ma = node2 .asExpr ( ) and
95+ ma .getQualifier ( ) = node1 .asExpr ( )
96+ )
97+ }
98+
99+ /**
100+ * Holds when a `KryoPool.borrow` method is called.
101+ */
102+ private predicate stepKryoPoolBorrowMethod ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
103+ exists ( MethodAccess ma |
104+ ma .getMethod ( ) =
105+ any ( Method m | m .getDeclaringType ( ) instanceof KryoPool and m .hasName ( "borrow" ) ) and
106+ node1 .asExpr ( ) = ma .getQualifier ( ) and
107+ node2 .asExpr ( ) = ma
108+ )
109+ }
51110}
52111
53112predicate unsafeDeserialization ( MethodAccess ma , Expr sink ) {
0 commit comments