public static void main(String[] args) { try { JSObject js1 = new JSObject(); JSObject js2 = new JSObject(); JSObject js3 = new JSObject(); js1.put("x", new ObjectValue("Y")); js2.put(new String("a"), new SecurityType(SecurityType.high, null)); js2.put(new String("u"), null); js3.put(new String("b"), null); // Testing the alloc function Heap h = new Heap(); Location l0 = h.alloc(Location.generateLocString(), js1); Location l1 = h.alloc("0", js1); Location l2 = h.alloc("10", js2); System.out.println("loc 1: " + l1); System.out.println("loc 2: " + l2); System.out.println("Heap : " + h); Heap h0 = h.deepClone(); Heap h1 = h.clone(); // Location l3 = h.alloc("5", js3); System.out.println("Heap comparison: " + h.equals(h0)); System.out.println("Heap comparison: " + h.equals(h1)); } catch (Exception e) { e.printStackTrace(); } }
/** * Method used to create dummy objects * * <p>The Object name contains the filename and line number at which the undefined variable is * being accessed * * <p>A new property at_Dummy is introduced to mark this node * * <p>TODO: Should the dummy object be marked tainted?? * * @param pre * @return */ public Location createDummyObjectInHeap(CommonTree ast, SecurityType dummy_type) { String taint_val = dummy_type.getObjValue(); if (taint_val == null) { taint_val = "@High"; } Location dummy_loc = this.dummyObjectMap.get(taint_val); if (dummy_loc == null) { Location second_result; // Add the low security type to the dummy object JSObject dummy_obj = PredefinedObjectTemplates.new_object("Object", NativeObjects.ObjectProt, dummy_type); dummy_obj.put("at_Dummy", new ObjectValue(true)); // current filename sans the path // String[] fn = currentfilename.split("/"); second_result = new Location("dummy_" + ast.getLine()); this.put(second_result, dummy_obj); this.dummyObjectMap.put(taint_val, second_result); return second_result; } else { return dummy_loc; } }
/** * add a (property, value) pair to an object at a given location * * @param l * @param property * @param ov */ public void add(Location l, String property, ObjectValue ov) { JSObject os; if (heap == null) { // if the heap is null heap = new TreeMap<Location, JSObject>(); } // if there are no entries in the heap or if there are no entries for the particular location if (heap.isEmpty() || !heap.containsKey(l)) { // create a new object for the location os = new JSObject(); // add the newly created object to the heap this.put(l, os); } // get the object for the heap location os = this.get(l); // add the current object value to every object in the ObjectSet os.put(property, ov); }