Skip to content

Commit

Permalink
Fix #877
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 8, 2016
1 parent d71de54 commit b2ccdee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Project: jackson-databind

2.7.8 (not yet released)

#877: @JsonIgnoreProperties`: ignoring the "cause" property of `Throwable` on GAE
#1359: Improve `JsonNode` deserializer to create `FloatNode` if parser supports
#1362: ObjectReader.readValues()` ignores offset and length when reading an array
(reported by wastevenson@github)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,15 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
AnnotatedMember mutator = propDef.getNonConstructorMutator();

if (ctxt.canOverrideAccessModifiers()) {
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
// [databind#877]: explicitly prevent forced access to `cause` of `Throwable`;
// never needed and attempts may cause problems on some platforms.
// !!! NOTE: should be handled better for 2.8 and later
if ((mutator instanceof AnnotatedField)
&& "cause".equals(mutator.getName())) {

This comment has been minimized.

Copy link
@davidkilliansc

davidkilliansc Sep 8, 2016

I have no context on the code, but could this impact non-Throwables that happen to have a member named "cause"?

This comment has been minimized.

Copy link
@cowtowncoder

cowtowncoder Sep 8, 2016

Author Member

Yes; I added one more check in the following check-in. Thank you for pointing this out!

;
} else {
mutator.fixAccess(ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
}
// note: this works since we know there's exactly one argument for methods
BeanProperty.Std property = new BeanProperty.Std(propDef.getFullName(),
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,26 +773,22 @@ public static void checkAndFixAccess(Member member, boolean force)
* always to make it accessible (latter because it will force
* skipping checks we have no use for...), so let's always call it.
*/
//if (!ao.isAccessible()) {
try {
if (force ||
(!Modifier.isPublic(member.getModifiers())
|| !Modifier.isPublic(member.getDeclaringClass().getModifiers()))) {
ao.setAccessible(true);
}
} catch (SecurityException se) {
/* 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on
* platforms like EJB and Google App Engine); so let's
* only fail if we really needed it...
*/
// 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on platforms like
// Google App Engine); so let's only fail if we really needed it...
if (!ao.isAccessible()) {
Class<?> declClass = member.getDeclaringClass();
throw new IllegalArgumentException("Can not access "+member+" (from class "+declClass.getName()+"; failed to set access: "+se.getMessage());
}
}
//}
}

/*
/**********************************************************
/* Enum type detection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.databind.misc;

import java.io.IOException;
import java.security.Permission;

import com.fasterxml.jackson.databind.*;

// Test(s) to verify that forced access works as expected
public class AccessFixTest extends BaseMapTest
{
static class CauseBlockingSecurityManager
extends SecurityManager
{
@Override
public void checkPermission(Permission perm) throws SecurityException {
if ("suppressAccessChecks".equals(perm.getName())) {
throw new SecurityException("Can not force permission: "+perm);
}
}
}

// [databind#877]: avoid forcing access to `cause` field of `Throwable`
// as it is never actually used (always call `initCause()` instead)
public void testCauseOfThrowableIgnoral() throws Exception
{
final SecurityManager origSecMan = System.getSecurityManager();
try {
System.setSecurityManager(new CauseBlockingSecurityManager());
_testCauseOfThrowableIgnoral();
} finally {
System.setSecurityManager(origSecMan);
}
}

private void _testCauseOfThrowableIgnoral() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.disable(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS);
IOException e = mapper.readValue("{}", IOException.class);
assertNotNull(e);
}
}

0 comments on commit b2ccdee

Please sign in to comment.