Commit 2963bb3f authored by Skylot's avatar Skylot

core: fix issues reported by coverity

parent 09a6ceac
...@@ -338,18 +338,23 @@ public class RegionMaker { ...@@ -338,18 +338,23 @@ public class RegionMaker {
InstructionRemover.unbindInsn(mth, exitInsn); InstructionRemover.unbindInsn(mth, exitInsn);
} }
block = getNextBlock(block); BlockNode body = getNextBlock(block);
if (body == null) {
mth.add(AFlag.INCONSISTENT_CODE);
LOG.warn("Unexpected end of synchronized block");
return null;
}
BlockNode exit; BlockNode exit;
if (exits.size() == 1) { if (exits.size() == 1) {
exit = getNextBlock(exits.iterator().next()); exit = getNextBlock(exits.iterator().next());
} else { } else {
cacheSet.clear(); cacheSet.clear();
exit = traverseMonitorExitsCross(block, exits, cacheSet); exit = traverseMonitorExitsCross(body, exits, cacheSet);
} }
stack.push(synchRegion); stack.push(synchRegion);
stack.addExit(exit); stack.addExit(exit);
synchRegion.getSubBlocks().add(makeRegion(block, stack)); synchRegion.getSubBlocks().add(makeRegion(body, stack));
stack.pop(); stack.pop();
return exit; return exit;
} }
......
...@@ -12,9 +12,18 @@ public class AsmUtils { ...@@ -12,9 +12,18 @@ public class AsmUtils {
} }
public static String getNameFromClassFile(File file) throws IOException { public static String getNameFromClassFile(File file) throws IOException {
FileInputStream in = new FileInputStream(file); String className = null;
FileInputStream in = null;
try {
in = new FileInputStream(file);
ClassReader classReader = new ClassReader(in); ClassReader classReader = new ClassReader(in);
return classReader.getClassName(); className = classReader.getClassName();
} finally {
if (in != null) {
in.close();
}
}
return className;
} }
} }
...@@ -102,12 +102,24 @@ public class InputFile { ...@@ -102,12 +102,24 @@ public class InputFile {
private static Dex loadFromClassFile(File file) throws IOException, DecodeException { private static Dex loadFromClassFile(File file) throws IOException, DecodeException {
File outFile = File.createTempFile("jadx-tmp-", System.nanoTime() + ".jar"); File outFile = File.createTempFile("jadx-tmp-", System.nanoTime() + ".jar");
outFile.deleteOnExit(); outFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(outFile); FileOutputStream out = null;
JarOutputStream jo = new JarOutputStream(out); JarOutputStream jo = null;
try {
out = new FileOutputStream(outFile);
jo = new JarOutputStream(out);
String clsName = AsmUtils.getNameFromClassFile(file); String clsName = AsmUtils.getNameFromClassFile(file);
if (clsName == null) {
throw new IOException("Can't read class name from file: " + file);
}
FileUtils.addFileToJar(jo, file, clsName + ".class"); FileUtils.addFileToJar(jo, file, clsName + ".class");
} finally {
if (jo != null) {
jo.close(); jo.close();
}
if (out != null) {
out.close(); out.close();
}
}
return loadFromJar(outFile); return loadFromJar(outFile);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment