diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/Config.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/Config.java index 9d448bb..3768d65 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/Config.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/Config.java @@ -48,8 +48,6 @@ public class Config { * checker framework. */ public static final String SERIALIZATION_ACTIVATION_FLAG = "enableSerialization"; - - public static final String DISABLE_LOCAL_VAR_OPT = "disableLocalVariableOptimization"; /** * Path to serialization config. If {@link #serializationActivation} is false, it will be {@code * null}. @@ -61,13 +59,12 @@ public class Config { */ @Nullable public final Path outputDir; - public final boolean disableLocalVariableOptimization; + public final boolean enableLocalVariableOptimization; /** Flag to control serialization internally. */ public final boolean serializationActivation; public Config(UCRTaintingChecker checker) { this.serializationActivation = checker.hasOption(SERIALIZATION_ACTIVATION_FLAG); - this.disableLocalVariableOptimization = checker.hasOption(DISABLE_LOCAL_VAR_OPT); if (serializationActivation && !checker.hasOption(SERIALIZATION_CONFIG_PATH)) { throw new RuntimeException( "Please specify the serialization config using the flag: " @@ -81,8 +78,8 @@ public Config(UCRTaintingChecker checker) { ? Paths.get(checker.getOptions().get(SERIALIZATION_CONFIG_PATH)) : null; String outputDirString = null; + Document document = null; if (configPath != null) { - Document document; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); @@ -94,6 +91,10 @@ public Config(UCRTaintingChecker checker) { throw new RuntimeException("Error in reading/parsing config at path: " + configPath, e); } } + this.enableLocalVariableOptimization = + Boolean.TRUE.equals( + XMLUtil.getValueFromTag(document, "/serialization/localVarOpt", Boolean.class) + .orElse(true)); this.outputDir = outputDirString == null ? null : Paths.get(outputDirString); } diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/SerializationService.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/SerializationService.java index 72e941d..36a597c 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/SerializationService.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/SerializationService.java @@ -95,7 +95,7 @@ public SerializationService(UCRTaintingChecker checker) { this.types = Types.instance(context); this.untaintedTypeMatchVisitor = TypeMatchVisitor.createUntaintedMatcher(typeFactory); this.polyTypeMatchVisitor = TypeMatchVisitor.createPolyTaintedMatcher(typeFactory); - this.fixComputer = new FixComputer(typeFactory, types, context); + this.fixComputer = new FixComputer(serializer.config, typeFactory, types, context); } /** diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/Serializer.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/Serializer.java index 0f15681..269e0c1 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/Serializer.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/Serializer.java @@ -52,7 +52,7 @@ public class Serializer { /** File name to write errors. */ public static final String ERROR_OUTPUT = "errors.json"; /** Config object used to configure the serializer. */ - private final Config config; + public final Config config; /** Path to write errors. */ private final @Nullable Path errorOutputPath; @@ -82,9 +82,7 @@ private void initializeOutputFiles() { Files.createDirectories(config.outputDir); try { Files.deleteIfExists(errorOutputPath); - Files.write( - config.outputDir.resolve("serialization_version.txt"), - ("0\n" + config.disableLocalVariableOptimization).getBytes()); + Files.write(config.outputDir.resolve("serialization_version.txt"), "0".getBytes()); } catch (IOException e) { throw new RuntimeException("Could not clear file at: " + errorOutputPath, e); } diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/DefaultTypeChangeVisitor.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/DefaultTypeChangeVisitor.java index 13b2515..9f6f585 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/DefaultTypeChangeVisitor.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/DefaultTypeChangeVisitor.java @@ -59,9 +59,15 @@ public class DefaultTypeChangeVisitor extends SpecializedFixComputer { /** Visitor that fixes all assignments on local variables. */ protected final LocalVariableFixVisitor localVariableFixVisitor; + protected final Config config; + public DefaultTypeChangeVisitor( - UCRTaintingAnnotatedTypeFactory factory, FixComputer fixComputer, Context context) { + Config config, + UCRTaintingAnnotatedTypeFactory factory, + FixComputer fixComputer, + Context context) { super(factory, fixComputer, context); + this.config = config; this.returnVisitor = new MethodReturnVisitor(typeFactory, fixComputer, context); this.types = Types.instance(context); this.localVariableFixVisitor = new LocalVariableFixVisitor(typeFactory, fixComputer, context); @@ -119,8 +125,7 @@ public Set visitIdentifier(IdentifierTree node, FoundRequired pair) { return Set.of(); } } - return fix.location.getKind().isLocalVariable() - && !typeFactory.getChecker().hasOption(Config.DISABLE_LOCAL_VAR_OPT) + return fix.location.getKind().isLocalVariable() && config.enableLocalVariableOptimization ? localVariableFixVisitor.visitIdentifier(node, pair) : Set.of(fix); } diff --git a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java index 2de0207..24b7242 100644 --- a/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java +++ b/src/main/java/edu/ucr/cs/riple/taint/ucrtainting/serialization/visitors/FixComputer.java @@ -36,6 +36,7 @@ import com.sun.tools.javac.code.Types; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.Context; +import edu.ucr.cs.riple.taint.ucrtainting.Config; import edu.ucr.cs.riple.taint.ucrtainting.FoundRequired; import edu.ucr.cs.riple.taint.ucrtainting.UCRTaintingAnnotatedTypeFactory; import edu.ucr.cs.riple.taint.ucrtainting.handlers.CollectionHandler; @@ -67,11 +68,12 @@ public class FixComputer extends SimpleTreeVisitor, FoundRequired> { protected final SpecializedFixComputer methodTypeArgumentFixVisitor; protected final CollectionFixVisitor collectionFixVisitor; - public FixComputer(UCRTaintingAnnotatedTypeFactory factory, Types types, Context context) { + public FixComputer( + Config config, UCRTaintingAnnotatedTypeFactory factory, Types types, Context context) { this.typeFactory = factory; this.context = context; this.types = types; - this.defaultTypeChangeVisitor = new DefaultTypeChangeVisitor(factory, this, context); + this.defaultTypeChangeVisitor = new DefaultTypeChangeVisitor(config, factory, this, context); this.unannotatedCodeFixComputer = new UnannotatedCodeFixVisitor(typeFactory, this, context); this.methodTypeArgumentFixVisitor = new GenericMethodFixVisitor(typeFactory, this, context); this.collectionFixVisitor = new CollectionFixVisitor(typeFactory, this, context);