Skip to content

Commit 6799f8f

Browse files
committed
Fix #1931
1 parent 939e332 commit 6799f8f

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project: jackson-databind
99
#1872 `NullPointerException` in `SubTypeValidator.validateSubType` when
1010
validating Spring interface
1111
(reported by Rob W)
12+
#1931: Two more `c3p0` gadgets to exploit default typing issue
1213

1314
2.7.9.2 (20-Dec-2017)
1415

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/SubTypeValidator.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
*/
1919
public class SubTypeValidator
2020
{
21-
protected final static String PREFIX_STRING = "org.springframework.";
21+
protected final static String PREFIX_SPRING = "org.springframework.";
22+
23+
protected final static String PREFIX_C3P0 = "com.mchange.v2.c3p0.";
24+
2225
/**
2326
* Set of well-known "nasty classes", deserialization of which is considered dangerous
2427
* and should (and is) prevented by default.
@@ -45,11 +48,13 @@ public class SubTypeValidator
4548
// [databind#1737]; 3rd party
4649
//s.add("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor"); // deprecated by [databind#1855]
4750
s.add("org.springframework.beans.factory.config.PropertyPathFactoryBean");
48-
s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
49-
s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
51+
52+
// s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource"); // deprecated by [databind#1931]
53+
// s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource"); // - "" -
5054
// [databind#1855]: more 3rd party
5155
s.add("org.apache.tomcat.dbcp.dbcp2.BasicDataSource");
5256
s.add("com.sun.org.apache.bcel.internal.util.ClassLoader");
57+
5358
DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s);
5459
}
5560

@@ -80,7 +85,9 @@ public void validateSubType(DeserializationContext ctxt, JavaType type) throws J
8085
// 18-Dec-2017, tatu: As per [databind#1855], need bit more sophisticated handling
8186
// for some Spring framework types
8287
// 05-Jan-2017, tatu: ... also, only applies to classes, not interfaces
83-
if (!raw.isInterface() && full.startsWith(PREFIX_STRING)) {
88+
if (raw.isInterface()) {
89+
;
90+
} else if (full.startsWith(PREFIX_SPRING)) {
8491
for (Class<?> cls = raw; (cls != null) && (cls != Object.class); cls = cls.getSuperclass()){
8592
String name = cls.getSimpleName();
8693
// looking for "AbstractBeanFactoryPointcutAdvisor" but no point to allow any is there?
@@ -90,6 +97,16 @@ public void validateSubType(DeserializationContext ctxt, JavaType type) throws J
9097
break main_check;
9198
}
9299
}
100+
} else if (full.startsWith(PREFIX_C3P0)) {
101+
// [databind#1737]; more 3rd party
102+
// s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
103+
// s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
104+
// [databind#1931]; more 3rd party
105+
// com.mchange.v2.c3p0.ComboPooledDataSource
106+
// com.mchange.v2.c3p0.debug.AfterCloseLoggingComboPooledDataSource
107+
if (full.endsWith("DataSource")) {
108+
break main_check;
109+
}
93110
}
94111
return;
95112
} while (false);

src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.fasterxml.jackson.annotation.JsonTypeInfo;
88
import com.fasterxml.jackson.databind.*;
9+
import com.mchange.v2.c3p0.jacksontest.ComboPooledDataSource;
910

1011
import java.util.ArrayList;
1112
import java.util.List;
@@ -86,23 +87,17 @@ public void testJDKTypes1855() throws Exception
8687

8788
// 17-Aug-2017, tatu: Ideally would test handling of 3rd party types, too,
8889
// but would require adding dependencies. This may be practical when
89-
// checking done by module, but for now let's not do that for databind.
90+
// checking done by separate module, but for now let's not do that for databind.
9091

9192
/*
9293
public void testSpringTypes1737() throws Exception
9394
{
9495
_testIllegalType("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor");
9596
_testIllegalType("org.springframework.beans.factory.config.PropertyPathFactoryBean");
9697
}
97-
98-
public void testC3P0Types1737() throws Exception
99-
{
100-
_testIllegalType("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
101-
_testIllegalType("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
102-
}
10398
*/
10499

105-
// // // Tests for [databind#1872]
100+
// // // Tests for [databind#1872]
106101
public void testJDKTypes1872() throws Exception
107102
{
108103
ObjectMapper mapper = new ObjectMapper();
@@ -113,6 +108,13 @@ public void testJDKTypes1872() throws Exception
113108
Authentication1872 result = mapper.readValue(json, Authentication1872.class);
114109
assertNotNull(result);
115110
}
111+
112+
// [databind#1931]
113+
public void testC3P0Types() throws Exception
114+
{
115+
_testIllegalType(ComboPooledDataSource.class); // [databind#1931]
116+
}
117+
116118
private void _testIllegalType(Class<?> nasty) throws Exception {
117119
_testIllegalType(nasty.getName());
118120
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.mchange.v2.c3p0.jacksontest;
2+
3+
// test class for [databind#1931]
4+
public class ComboPooledDataSource {
5+
6+
}

0 commit comments

Comments
 (0)