[Fb-contrib-commit] SF.net SVN: fb-contrib:[1657] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2011-03-06 16:59:36
|
Revision: 1657
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1657&view=rev
Author: dbrosius
Date: 2011-03-06 16:59:29 +0000 (Sun, 06 Mar 2011)
Log Message:
-----------
add ability to ignore BAS from method calls that are risky
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2011-03-06 16:36:11 UTC (rev 1656)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2011-03-06 16:59:29 UTC (rev 1657)
@@ -47,6 +47,11 @@
*/
public class BloatedAssignmentScope extends BytecodeScanningDetector
{
+ private static final Set<String> dangerousAssignmentSources = new HashSet<String>();
+ static {
+ dangerousAssignmentSources.add("java/lang/System.currentTimeMillis()J");
+ }
+
BugReporter bugReporter;
private OpcodeStack stack;
private Set<Integer> ignoreRegs;
@@ -145,7 +150,7 @@
*/
@Override
public void sawOpcode(int seen) {
- Comparable<?> caller = null;
+ UserObject uo = null;
try {
if ((seen == ASTORE)
|| (seen == ISTORE)
@@ -160,6 +165,7 @@
int reg = RegisterUtils.getStoreReg(this, seen);
Integer iReg = Integer.valueOf(reg);
int pc = getPC();
+
if (catchHandlers.contains(Integer.valueOf(pc)))
{
ignoreRegs.add(iReg);
@@ -176,14 +182,19 @@
if (!ignoreRegs.contains(iReg)) {
ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
if (sb != null) {
- Object assoc = null;
+ UserObject assoc = null;
if (stack.getStackDepth() > 0) {
- assoc = stack.getStackItem(0).getUserValue();
+ assoc = (UserObject)stack.getStackItem(0).getUserValue();
}
- sb.addStore(reg, pc, assoc);
- if (sawDup)
- {
- sb.addLoad(reg, pc);
+
+ if ((assoc != null) && assoc.isRisky) {
+ ignoreRegs.add(iReg);
+ } else {
+ sb.addStore(reg, pc, assoc);
+ if (sawDup)
+ {
+ sb.addLoad(reg, pc);
+ }
}
}
else
@@ -332,15 +343,19 @@
dontReport = true;
}
- caller = getCallingObject();
+ uo = new UserObject();
+ uo.isRisky = isRiskyMethodCall();
+ uo.caller = getCallingObject();
- if (caller != null) {
+ if (uo.caller != null) {
ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
if (sb != null) {
- sb.removeByAssoc(caller);
+ sb.removeByAssoc(uo.caller);
}
}
-
+ } else if ((seen == INVOKESTATIC) || (seen == INVOKESPECIAL)) {
+ uo = new UserObject();
+ uo.isRisky = isRiskyMethodCall();
} else if (seen == MONITORENTER) {
monitorSyncPCs.add(Integer.valueOf(getPC()));
} else if (seen == MONITOREXIT) {
@@ -354,10 +369,10 @@
sawNull = (seen == ACONST_NULL);
} finally {
stack.sawOpcode(this, seen);
- if (caller != null) {
+ if (uo != null) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
- item.setUserValue(caller);
+ item.setUserValue(uo);
}
}
}
@@ -462,7 +477,7 @@
private boolean isGoto;
private Map<Integer, Integer> loads;
private Map<Integer, Integer> stores;
- private Map<Object, Integer> assocs;
+ private Map<UserObject, Integer> assocs;
private List<ScopeBlock> children;
/** construts a new scope block
@@ -574,7 +589,7 @@
* @param reg the register that was stored
* @param pc the instruction that did the store
*/
- public void addStore(int reg, int pc, Object assocObject) {
+ public void addStore(int reg, int pc, UserObject assocObject) {
if (stores == null)
{
stores = new HashMap<Integer, Integer>();
@@ -583,7 +598,7 @@
stores.put(Integer.valueOf(reg), Integer.valueOf(pc));
if (assocs == null)
{
- assocs = new HashMap<Object, Integer>();
+ assocs = new HashMap<UserObject, Integer>();
}
assocs.put(assocObject, Integer.valueOf(reg));
}
@@ -781,4 +796,14 @@
}
}
}
+
+ public boolean isRiskyMethodCall() {
+ String key = getClassConstantOperand() + "." + getNameConstantOperand() + getSigConstantOperand();
+ return dangerousAssignmentSources.contains(key);
+ }
+
+ class UserObject {
+ Comparable<?> caller;
+ boolean isRisky;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|