Skip to content

Commit

Permalink
Add some alternative method sets to trace.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbechler committed Apr 17, 2017
1 parent c5a1c60 commit 85cff0a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
42 changes: 36 additions & 6 deletions src/main/java/serianalyzer/InitialSetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,57 @@ public enum InitialSetType {
JAVA,

/**
* JAVA + bean getter methods
* bean getter methods
*/
GETTERS,

/**
* JAVA + bean setter methods
* bean setter methods
*/
SETTERS,

/**
* JAVA + zero argument methods
* zero argument methods
*/
ZEROARGMETHOD,

/**
* JAVA + zero argument constructor
* zero argument constructor
*/
DEFAULTCONST,

/**
* JAVA + one argument string constructor
* one argument string constructor
*/
STRINGCONST
STRINGCONST,

/**
* all constructors
*/
ALLCONST,

/**
* Finalizers
*/
FINALIZE,

/**
* Methods commonly called (toString(),hashCode(),equals(Object),java.lang.Comparable->compareTo(Object))
*/
COMMON,

/**
* Castor extra methods addXXX/createXXX
*/
CASTOR,

/**
* Proxy invocation handler
*/
PROXY,

/**
* readReplace invocation
*/
READ_RESOLVE
}
3 changes: 3 additions & 0 deletions src/main/java/serianalyzer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ else if ( "-t".equals(arg) || "--initialSet".equals(arg) ) { //$NON-NLS-1$ //$NO
else if ( "-a".equals(arg) || "--allTypes".equals(arg) ) { //$NON-NLS-1$ //$NON-NLS-2$
includeNonSerializable = true;
}
else if ( "-j".equals(arg) || "--noJavaDeserializtion".equals(arg) ) { //$NON-NLS-1$ //$NON-NLS-2$
excludeJavaSerialization = true;
}
else {
break;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/serianalyzer/Serianalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,24 @@ private Collection<MethodReference> dumpMethodCalls ( Collection<MethodReference
cal = cal.comparable();

if ( this.input.getConfig().isWhitelisted(cal) ) {
if ( log.isDebugEnabled() ) {
log.debug("Is whitelisted " + cal); //$NON-NLS-1$
}
continue;
}

Set<MethodReference> callers = this.state.getMethodCallers().get(cal);
if ( callers == null || callers.isEmpty() ) {
if ( log.isDebugEnabled() ) {
log.debug("Does not have caller " + cal); //$NON-NLS-1$
}
continue;
}

if ( !dumpBacktraces(cal, this.state.getInitial(), usedInstantiable, "", maxDumps) ) { //$NON-NLS-1$
if ( log.isDebugEnabled() ) {
log.debug("Not determined to be reachable " + cal); //$NON-NLS-1$
}
continue;
}
System.out.flush();
Expand Down Expand Up @@ -981,8 +990,8 @@ public boolean checkMethodCall ( MethodReference initialRef, Set<MethodReference
}

if ( this.getConfig().isStopMethod(initialRef) ) {
this.state.traceCalls(initialRef, cal);
if ( this.reported.add(initialRef.comparable()) ) {
this.state.traceCalls(initialRef, cal);
this.getState().reportCall(initialRef);
Verbose.println(String.format(
"Encountered method %s->%s %s", //$NON-NLS-1$
Expand Down
50 changes: 46 additions & 4 deletions src/main/java/serianalyzer/SerianalyzerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ public boolean isExtraCheckMethod ( MethodReference ref, boolean classSerializab
case STRINGCONST:
m = isStringConstructor(ref);
break;
case ALLCONST:
m = "<init>".equals(ref.getMethod());
break;
case FINALIZE:
m = "finalize".equals(ref.getMethod());
break;
case COMMON:
m = isCommonMethod(ref);
break;
case CASTOR:
m = isCastorExtraMethod(ref);
break;
case PROXY:
m = "invoke".equals(ref.getMethod()) //$NON-NLS-1$
&& "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;" //$NON-NLS-1$
.equals(ref.getSignature());
break;
case READ_RESOLVE:
m = "readResolve".equals(ref.getMethod());
break;
default:
break;
}
Expand Down Expand Up @@ -475,7 +495,8 @@ public void setCheckJavaSerialization ( boolean checkJavaSerialization ) {
*/
private static boolean isSetter ( MethodReference ref ) {
Type[] args = Type.getArgumentTypes(ref.getSignature());
return !ref.isStatic() && ref.getMethod().startsWith("set") && ref.getSignature().endsWith(")V") && args.length == 1;
return !ref.isStatic() && ref.getMethod().startsWith("set") && ref.getMethod().length() > 3
&& Character.isUpperCase(ref.getMethod().charAt(3)) && ref.getSignature().endsWith(")V") && args.length == 1;
}


Expand All @@ -495,7 +516,27 @@ protected boolean isNoArgMethod ( MethodReference ref ) {


protected boolean isGetter ( MethodReference ref ) {
return ref.getMethod().startsWith("get") && ref.getSignature().startsWith("()");
return !ref.isStatic() && ref.getMethod().startsWith("get") && ref.getSignature().startsWith("()");
}


/**
* @param ref
* @return
*/
private static boolean isCommonMethod ( MethodReference ref ) {
return !ref.isStatic() && ( "hashCode".equals(ref.getMethod()) || "equals".equals(ref.getMethod()) || "toString".equals(ref.getMethod())
|| "compareTo".equals(ref.getMethod()) );
}


/**
* @param ref
* @return
*/
private static boolean isCastorExtraMethod ( MethodReference ref ) {
return !ref.isStatic()
&& ( ref.getMethod().startsWith("add") || ( ref.getMethod().startsWith("create") && ref.getSignature().startsWith("()") ) );
}


Expand All @@ -515,8 +556,8 @@ public boolean isDumpPrivileged () {
* @return whether
*/
public boolean isConsiderReachable ( boolean serializable, String name, String signature, int access ) {
return ( serializable && "toString".equals(name) ) || ( serializable && "hashCode".equals(name) ) || ( serializable && "equals".equals(name) )
|| ( serializable && "compareTo".equals(name) );
boolean include = this.checkNonSerializable || serializable;
return ( include && "hashCode".equals(name) ) || ( include && "equals".equals(name) ) || ( include && "compareTo".equals(name) );
}


Expand All @@ -535,6 +576,7 @@ public boolean isStopMethod ( MethodReference ref ) {
|| ( ref.getTypeNameString().endsWith(".TemplatesImpl") && ref.getMethod().equals("newTransformer") )
|| ( ref.getTypeNameString().equals("java.net.URLClassLoader") && ref.getMethod().equals("newInstance") )
|| ( ref.getTypeNameString().equals("java.io.ObjectInputStream") && ref.getMethod().equals("<init>") )
|| ( ref.getTypeNameString().equals("java.lang.ClassLoader") && ref.getMethod().endsWith("loadClass") )
|| ref.getMethod().equals("halt") ) {
return true;
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/serianalyzer/SerianalyzerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,6 @@ void reportCall ( MethodReference ref ) {
* @param ref
*/
void addInitial ( MethodReference ref ) {
/*
* if ( !initial.contains( ref.comparable() ) ) {
* System.err.println( "Initial method found: " + String.format( "%s->%s %s", ref.getTypeNameString(),
* ref.getMethod(), ref.getSignature() ) );
* }
*/

this.initial.add(ref.comparable());
}

Expand Down

0 comments on commit 85cff0a

Please sign in to comment.