output
stringlengths
64
73.2k
input
stringlengths
208
73.3k
instruction
stringclasses
1 value
#fixed code private void sendTelemetryData(final LinkWrapper link, final ProtonDelivery delivery, final Message msg) { if (!delivery.remotelySettled()) { LOG.trace("received un-settled telemetry message on link [{}]", link.getLinkId()); } final ResourceIdentifier messageAddress = ResourceIdentifier.fromString(getAnnotation(msg, APP_PROPERTY_RESOURCE_ID, String.class)); checkDeviceExists(messageAddress, deviceExists -> { if (deviceExists) { vertx.runOnContext(run -> { final String messageId = UUID.randomUUID().toString(); final AmqpMessage amqpMessage = AmqpMessage.of(msg, delivery); vertx.sharedData().getLocalMap(dataAddress).put(messageId, amqpMessage); sendAtMostOnce(link, messageId, delivery); }); } else { LOG.debug("device {}/{} does not exist, closing link", messageAddress.getTenantId(), messageAddress.getDeviceId()); MessageHelper.rejected(delivery, AmqpError.PRECONDITION_FAILED.toString(), "device does not exist"); onLinkDetach(link); } }); }
#vulnerable code private void sendTelemetryData(final LinkWrapper link, final ProtonDelivery delivery, final Message msg) { if (!delivery.remotelySettled()) { LOG.trace("received un-settled telemetry message on link [{}]", link.getLinkId()); } final ResourceIdentifier messageAddress = ResourceIdentifier.fromString(MessageHelper.getAnnotation(msg, APP_PROPERTY_RESOURCE_ID)); checkDeviceExists(messageAddress, deviceExists -> { if (deviceExists) { vertx.runOnContext(run -> { final String messageId = UUID.randomUUID().toString(); final AmqpMessage amqpMessage = AmqpMessage.of(msg, delivery); vertx.sharedData().getLocalMap(dataAddress).put(messageId, amqpMessage); sendAtMostOnce(link, messageId, delivery); }); } else { LOG.debug("Device {}/{} does not exist, rejecting message.", messageAddress.getTenantId(), messageAddress.getDeviceId()); ProtonHelper.rejected(delivery, true); onLinkDetach(link); } }); } #location 5 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 11 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws IOException { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 12 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscCloseLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); }
#vulnerable code @Test public void TestEscCloseLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestIntOnly() throws Exception { // Is this valid for GeoJSON? ArrayList<Object> stuff = new ArrayList<Object>(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int"); SerDe jserde = mkSerDe(proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); //value.set("{\"properties\":{\"num\":7}}"); addWritable(stuff, 7); Object row = runSerDe(stuff, jserde, rowOI); Object fieldData = getField("num", row, rowOI); Assert.assertEquals(7, ((IntWritable)fieldData).get()); stuff.clear(); addWritable(stuff, 9); row = runSerDe(stuff, jserde, rowOI); fieldData = getField("num", row, rowOI); Assert.assertEquals(9, ((IntWritable)fieldData).get()); }
#vulnerable code @Test public void TestIntOnly() throws Exception { // Is this valid for GeoJSON? Configuration config = new Configuration(); Text value = new Text(); SerDe jserde = new GeoJsonSerDe(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int"); jserde.initialize(config, proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); value.set("{\"properties\":{\"num\":7}}"); Object row = jserde.deserialize(value); StructField f0 = rowOI.getStructFieldRef("num"); Object fieldData = rowOI.getStructFieldData(row, f0); Assert.assertEquals(7, ((IntWritable)fieldData).get()); value.set("{\"properties\":{\"num\":9}}"); row = jserde.deserialize(value); f0 = rowOI.getStructFieldRef("num"); fieldData = rowOI.getStructFieldData(row, f0); Assert.assertEquals(9, ((IntWritable)fieldData).get()); } #location 15 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 11 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 14 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscSlashLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); }
#vulnerable code @Test public void TestEscSlashLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestGeomFirst() throws Exception { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); }
#vulnerable code @Test public void TestGeomFirst() throws IOException { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscCloseLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); }
#vulnerable code @Test public void TestEscCloseLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestGeomFirst() throws Exception { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); }
#vulnerable code @Test public void TestGeomFirst() throws IOException { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscPoints() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); }
#vulnerable code @Test public void TestEscPoints() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscSlashLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); }
#vulnerable code @Test public void TestEscSlashLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 12 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws IOException { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestNullAttr() throws Exception { ArrayList<Object> stuff = new ArrayList<Object>(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int"); SerDe jserde = mkSerDe(proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); //value.set("{\"properties\":{\"num\":7}}"); addWritable(stuff, 7); Object row = runSerDe(stuff, jserde, rowOI); Object fieldData = getField("num", row, rowOI); Assert.assertEquals(7, ((IntWritable)fieldData).get()); //value.set("{\"properties\":{}}"); stuff.set(0, null); row = runSerDe(stuff, jserde, rowOI); fieldData = getField("num", row, rowOI); Assert.assertNull(fieldData); }
#vulnerable code @Test public void TestNullAttr() throws Exception { Configuration config = new Configuration(); Text value = new Text(); SerDe jserde = new GeoJsonSerDe(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int"); jserde.initialize(config, proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); value.set("{\"properties\":{\"num\":7}}"); Object row = jserde.deserialize(value); StructField f0 = rowOI.getStructFieldRef("num"); Object fieldData = rowOI.getStructFieldData(row, f0); Assert.assertEquals(7, ((IntWritable)fieldData).get()); value.set("{\"properties\":{}}"); row = jserde.deserialize(value); f0 = rowOI.getStructFieldRef("num"); fieldData = rowOI.getStructFieldData(row, f0); Assert.assertEquals(null, fieldData); } #location 15 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscCloseLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); }
#vulnerable code @Test public void TestEscCloseLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscSlashLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); }
#vulnerable code @Test public void TestEscSlashLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestGeomFirst() throws Exception { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); }
#vulnerable code @Test public void TestGeomFirst() throws IOException { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscSlashLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); }
#vulnerable code @Test public void TestEscSlashLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws IOException { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 15 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 14 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscPoints() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); }
#vulnerable code @Test public void TestEscPoints() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws IOException { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestGeomFirst() throws Exception { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); }
#vulnerable code @Test public void TestGeomFirst() throws IOException { Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true)); } #location 3 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscCloseLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); }
#vulnerable code @Test public void TestEscCloseLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 14 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 15 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private static void validatePoint(Point point, BytesWritable geometryAsWritable) { ST_X getX = new ST_X(); ST_Y getY = new ST_Y(); DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable); DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable); if (null == xAsWritable || null == yAsWritable || Math.abs(point.getX() - xAsWritable.get()) > Epsilon || Math.abs(point.getY() - yAsWritable.get()) > Epsilon) System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable) + " ~ " + point); assertNotNull("The x writable must not be null!", xAsWritable); assertNotNull("The y writable must not be null!", yAsWritable); assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon); assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon); }
#vulnerable code private static void validatePoint(Point point, BytesWritable geometryAsWritable) { ST_X getX = new ST_X(); DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable); assertNotNull("The x writable must not be null!", xAsWritable); ST_Y getY = new ST_Y(); DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable); assertNotNull("The y writable must not be null!", yAsWritable); assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon); assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon); } #location 10 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEachOnce() throws Exception { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); }
#vulnerable code @Test public void TestEachOnce() throws IOException { //Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68 Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121))); Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187))); Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264))); Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412))); Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41))); // Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private UnenclosedJsonRecordReader getReaderFor(String resource, int start, int end) throws Exception { Path path = new Path(this.getClass().getResource(resource).getFile()); FileSplit split = new FileSplit(path, start, end - start, new String[0]); UnenclosedJsonRecordReader rr = new UnenclosedJsonRecordReader(); try { TaskAttemptContext tac = createTaskAttemptContext(new Configuration(), new TaskAttemptID()); rr.initialize(split, tac); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } return rr; }
#vulnerable code private UnenclosedJsonRecordReader getReaderFor(String resource, int start, int end) throws IOException { Path path = new Path(this.getClass().getResource(resource).getFile()); JobConf conf = new JobConf(); FileSplit split = new FileSplit(path, start, end - start, new String[0]); return new UnenclosedJsonRecordReader(split, conf); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscCloseLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); }
#vulnerable code @Test public void TestEscCloseLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscAposLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); }
#vulnerable code @Test public void TestEscAposLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140))); } #location 6 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscPoints() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); }
#vulnerable code @Test public void TestEscPoints() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true)); Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true)); Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true)); } #location 5 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscQuoteLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); }
#vulnerable code @Test public void TestEscQuoteLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140))); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 11 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 9 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscape() throws Exception { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); }
#vulnerable code @Test public void TestEscape() throws IOException { // Issue #68 //int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395 Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140))); Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140))); Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289))); Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}" Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68))); Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69))); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestIntPoint() throws Exception { ArrayList<Object> stuff = new ArrayList<Object>(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num,shape"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "bigint,binary"); SerDe jserde = mkSerDe(proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); // value.set("{\"properties\":{\"num\":7},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}"); addWritable(stuff, 7L); addWritable(stuff, new Point(15.0, 5.0)); Object row = runSerDe(stuff, jserde, rowOI); Object fieldData = getField("num", row, rowOI); Assert.assertEquals(7, ((LongWritable)fieldData).get()); //value.set("{\"properties\":{\"num\":4},\"geometry\":{\"type\":\"Point\",\"coordinates\":[7.0,2.0]}}"); stuff.clear(); addWritable(stuff, 4L); addWritable(stuff, new Point(7.0, 2.0)); row = runSerDe(stuff, jserde, rowOI); fieldData = getField("num", row, rowOI); Assert.assertEquals(4, ((LongWritable)fieldData).get()); fieldData = getField("shape", row, rowOI); ckPoint(new Point(7.0, 2.0), (BytesWritable)fieldData); }
#vulnerable code @Test public void TestIntPoint() throws Exception { Configuration config = new Configuration(); Text value = new Text(); SerDe jserde = new GeoJsonSerDe(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num,shape"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "bigint,binary"); jserde.initialize(config, proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); value.set("{\"properties\":{\"num\":7},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}"); Object row = jserde.deserialize(value); StructField fref = rowOI.getStructFieldRef("num"); Object fieldData = rowOI.getStructFieldData(row, fref); Assert.assertEquals(7, ((LongWritable)fieldData).get()); value.set("{\"properties\":{\"num\":4},\"geometry\":{\"type\":\"Point\",\"coordinates\":[7.0,2.0]}}"); row = jserde.deserialize(value); fref = rowOI.getStructFieldRef("num"); fieldData = rowOI.getStructFieldData(row, fref); Assert.assertEquals(4, ((LongWritable)fieldData).get()); fref = rowOI.getStructFieldRef("shape"); fieldData = rowOI.getStructFieldData(row, fref); ckPoint(new Point(7.0, 2.0), (BytesWritable)fieldData); } #location 15 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscSlashLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); }
#vulnerable code @Test public void TestEscSlashLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 7 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); }
#vulnerable code @Test public void TestArbitrarySplitLocations() throws Exception { //int totalSize = 415; //int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41))); Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123))); Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123))); Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123))); Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415))); Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415))); } #location 10 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestNullGeom() throws Exception { ArrayList<Object> stuff = new ArrayList<Object>(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary"); SerDe jserde = mkSerDe(proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); //value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}"); addWritable(stuff, new Point(15.0, 5.0)); Object row = runSerDe(stuff, jserde, rowOI); Object fieldData = getField("shape", row, rowOI); ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData); //value.set("{\"properties\":{},\"coordinates\":null}"); stuff.set(0, null); row = runSerDe(stuff, jserde, rowOI); fieldData = getField("shape", row, rowOI); Assert.assertNull(fieldData); }
#vulnerable code @Test public void TestNullGeom() throws Exception { Configuration config = new Configuration(); Text value = new Text(); SerDe jserde = new GeoJsonSerDe(); Properties proptab = new Properties(); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape"); proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary"); jserde.initialize(config, proptab); StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector(); value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}"); Object row = jserde.deserialize(value); StructField f0 = rowOI.getStructFieldRef("shape"); Object fieldData = rowOI.getStructFieldData(row, f0); ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData); value.set("{\"properties\":{},\"coordinates\":null}"); row = jserde.deserialize(value); f0 = rowOI.getStructFieldRef("shape"); fieldData = rowOI.getStructFieldData(row, f0); Assert.assertEquals(null, fieldData); } #location 15 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestWhitespace() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Test public void TestWhitespace() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 13 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Ignore // May not be guaranteed behavior public void TestComma() throws Exception { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); }
#vulnerable code @Ignore // May not be guaranteed behavior public void TestComma() throws IOException { //int [] recordBreaks = new int[] { 0, 57, 111, , }; int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true); Assert.assertEquals(4, rslt.length); int[] before = null, after = null; before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true); Assert.assertEquals(4, before.length + after.length); before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true); after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true); Assert.assertEquals(4, before.length + after.length); } #location 13 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private static void validatePoint(Point point, BytesWritable geometryAsWritable) { ST_X getX = new ST_X(); ST_Y getY = new ST_Y(); DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable); DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable); if (null == xAsWritable || null == yAsWritable || Math.abs(point.getX() - xAsWritable.get()) > Epsilon || Math.abs(point.getY() - yAsWritable.get()) > Epsilon) System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable) + " ~ " + point); assertNotNull("The x writable must not be null!", xAsWritable); assertNotNull("The y writable must not be null!", yAsWritable); assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon); assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon); }
#vulnerable code private static void validatePoint(Point point, BytesWritable geometryAsWritable) { ST_X getX = new ST_X(); DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable); assertNotNull("The x writable must not be null!", xAsWritable); ST_Y getY = new ST_Y(); DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable); assertNotNull("The y writable must not be null!", yAsWritable); assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon); assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon); } #location 11 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void TestEscOpenLast() throws Exception { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); }
#vulnerable code @Test public void TestEscOpenLast() throws IOException { //int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , }; Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45))); Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140))); Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140))); Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280))); } #location 8 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private PackrOutput buildMacBundle(PackrOutput output) throws IOException { if (config.platform != PackrConfig.Platform.MacOS) { return output; } // replacement strings for Info.plist Map<String, String> values = new HashMap<>(); values.put("${executable}", config.executable); if (config.bundleIdentifier != null) { values.put("${bundleIdentifier}", config.bundleIdentifier); } else { values.put("${bundleIdentifier}", config.mainClass.substring(0, config.mainClass.lastIndexOf('.'))); } // create folder structure File root = output.executableFolder; PackrFileUtils.mkdirs(new File(root, "Contents")); try (FileWriter info = new FileWriter(new File(root, "Contents/Info.plist"))) { String plist = readResourceAsString("/Info.plist", values); info.write(plist); } File target = new File(root, "Contents/MacOS"); PackrFileUtils.mkdirs(target); File resources = new File(root, "Contents/Resources"); PackrFileUtils.mkdirs(resources); if (config.iconResource != null) { // copy icon to Contents/Resources/icons.icns if (config.iconResource.exists()) { PackrFileUtils.copyFile(config.iconResource, new File(resources, "icons.icns")); } } return new PackrOutput(target, resources); }
#vulnerable code private PackrOutput buildMacBundle(PackrOutput output) throws IOException { if (config.platform != PackrConfig.Platform.MacOS) { return output; } // replacement strings for Info.plist Map<String, String> values = new HashMap<>(); values.put("${executable}", config.executable); if (config.bundleIdentifier != null) { values.put("${bundleIdentifier}", config.bundleIdentifier); } else { values.put("${bundleIdentifier}", config.mainClass.substring(0, config.mainClass.lastIndexOf('.'))); } // create folder structure File root = output.executableFolder; PackrFileUtils.mkdirs(new File(root, "Contents")); new FileWriter(new File(root, "Contents/Info.plist")).write(readResourceAsString("/Info.plist", values)); File target = new File(root, "Contents/MacOS"); PackrFileUtils.mkdirs(target); File resources = new File(root, "Contents/Resources"); PackrFileUtils.mkdirs(resources); if (config.iconResource != null) { // copy icon to Contents/Resources/icons.icns if (config.iconResource.exists()) { PackrFileUtils.copyFile(config.iconResource, new File(resources, "icons.icns")); } } return new PackrOutput(target, resources); } #location 23 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private void copyExecutableAndClasspath(PackrOutput output) throws IOException { byte[] exe = null; String extension = ""; switch (config.platform) { case Windows32: exe = readResource("/packr-windows.exe"); extension = ".exe"; break; case Windows64: exe = readResource("/packr-windows-x64.exe"); extension = ".exe"; break; case Linux32: exe = readResource("/packr-linux"); break; case Linux64: exe = readResource("/packr-linux-x64"); break; case MacOS: exe = readResource("/packr-mac"); break; } System.out.println("Copying executable ..."); try (OutputStream writer = new FileOutputStream( new File(output.executableFolder, config.executable + extension))) { writer.write(exe); } PackrFileUtils.chmodX(new File(output.executableFolder, config.executable + extension)); System.out.println("Copying classpath(s) ..."); for (String file : config.classpath) { File cpSrc = new File(file); File cpDst = new File(output.resourcesFolder, new File(file).getName()); if (cpSrc.isFile()) { PackrFileUtils.copyFile(cpSrc, cpDst); } else if (cpSrc.isDirectory()) { PackrFileUtils.copyDirectory(cpSrc, cpDst); } else { System.err.println("Warning! Classpath not found: " + cpSrc); } } }
#vulnerable code private void copyExecutableAndClasspath(PackrOutput output) throws IOException { byte[] exe = null; String extension = ""; switch (config.platform) { case Windows32: exe = readResource("/packr-windows.exe"); extension = ".exe"; break; case Windows64: exe = readResource("/packr-windows-x64.exe"); extension = ".exe"; break; case Linux32: exe = readResource("/packr-linux"); break; case Linux64: exe = readResource("/packr-linux-x64"); break; case MacOS: exe = readResource("/packr-mac"); break; } System.out.println("Copying executable ..."); new FileOutputStream(new File(output.executableFolder, config.executable + extension)).write(exe); PackrFileUtils.chmodX(new File(output.executableFolder, config.executable + extension)); System.out.println("Copying classpath(s) ..."); for (String file : config.classpath) { File cpSrc = new File(file); File cpDst = new File(output.resourcesFolder, new File(file).getName()); if (cpSrc.isFile()) { PackrFileUtils.copyFile(cpSrc, cpDst); } else if (cpSrc.isDirectory()) { PackrFileUtils.copyDirectory(cpSrc, cpDst); } else { System.err.println("Warning! Classpath not found: " + cpSrc); } } } #location 26 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private void writeConfig(PackrOutput output) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("{\n"); builder.append(" \"classPath\": ["); String delim = "\n"; for (String f : config.classpath) { builder.append(delim).append(" \"").append(new File(f).getName()).append("\""); delim = ",\n"; } builder.append("\n ],\n"); builder.append(" \"mainClass\": \"").append(config.mainClass).append("\",\n"); builder.append(" \"vmArgs\": [\n"); for (int i = 0; i < config.vmArgs.size(); i++) { String vmArg = config.vmArgs.get(i); builder.append(" \""); if (!vmArg.startsWith("-")) { builder.append("-"); } builder.append(vmArg).append("\""); if (i < config.vmArgs.size() - 1) { builder.append(","); } builder.append("\n"); } builder.append(" ]\n"); builder.append("}"); try (Writer writer = new FileWriter(new File(output.resourcesFolder, "config.json"))) { writer.write(builder.toString()); } }
#vulnerable code private void writeConfig(PackrOutput output) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("{\n"); builder.append(" \"classPath\": ["); String delim = "\n"; for (String f : config.classpath) { builder.append(delim).append(" \"").append(new File(f).getName()).append("\""); delim = ",\n"; } builder.append("\n ],\n"); builder.append(" \"mainClass\": \"").append(config.mainClass).append("\",\n"); builder.append(" \"vmArgs\": [\n"); for (int i = 0; i < config.vmArgs.size(); i++) { String vmArg = config.vmArgs.get(i); builder.append(" \""); if (!vmArg.startsWith("-")) { builder.append("-"); } builder.append(vmArg).append("\""); if (i < config.vmArgs.size() - 1) { builder.append(","); } builder.append("\n"); } builder.append(" ]\n"); builder.append("}"); new FileWriter(new File(output.resourcesFolder, "config.json")).write(builder.toString()); } #location 32 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public Promise synwrite(BaseMessage message){ Channel ch = fetchOneWritable(); if(ch == null) return null; AbstractSessionStateManager session = (AbstractSessionStateManager)ch.pipeline().get(sessionHandler); return session.writeMessagesync( message); }
#vulnerable code public Promise synwrite(BaseMessage message){ Channel ch = fetchOneWritable(); AbstractSessionStateManager session = (AbstractSessionStateManager)ch.pipeline().get(sessionHandler); return session.writeMessagesync( message); } #location 3 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public ChannelFuture asynwrite(Object msg){ Channel ch = fetchOneWritable(); if(ch == null) return null; ChannelFuture future = ch.writeAndFlush(msg); return future; }
#vulnerable code public ChannelFuture asynwrite(Object msg){ Channel ch = fetchOneWritable(); ChannelFuture future = ch.writeAndFlush(msg); return future; } #location 3 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code private Class<?> loadTestClassWithDistinctClassLoader() throws Exception { URL[] classpath = {temp.getRoot().toURI().toURL()}; URLClassLoader loader = new URLClassLoader(classpath); Class<?> clazz = loader.loadClass(CLASS_NAME); loader.close(); return clazz; }
#vulnerable code private Class<?> loadTestClassWithDistinctClassLoader() throws Exception { URL[] classpath = {temp.getRoot().toURI().toURL()}; URLClassLoader loader = new URLClassLoader(classpath); return loader.loadClass(CLASS_NAME); } #location 4 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Override public void disconnect() { if (!isConnected()) { logger.error("ClusterManager " + _instanceName + " already disconnected"); return; } disconnectInternal(); }
#vulnerable code @Override public void disconnect() { if (!isConnected()) { logger.warn("ClusterManager " + _instanceName + " already disconnected"); return; } logger.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName); /** * shutdown thread pool first to avoid reset() being invoked in the middle of state * transition */ _messagingService.getExecutor().shutDown(); resetHandlers(); _helixAccessor.shutdown(); if (_leaderElectionHandler != null) { _leaderElectionHandler.reset(); } if (_participantHealthCheckInfoCollector != null) { _participantHealthCheckInfoCollector.stop(); } if (_timer != null) { _timer.cancel(); _timer = null; } if (_instanceType == InstanceType.CONTROLLER) { stopTimerTasks(); } // unsubscribe accessor from controllerChange _zkClient.unsubscribeAll(); _zkClient.close(); // HACK seems that zkClient is not sending DISCONNECT event _zkStateChangeListener.disconnect(); logger.info("Cluster manager: " + _instanceName + " disconnected"); } #location 25 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test (groups = {"integrationTest"}) public void testFileBasedClusterManager() throws Exception { List<FileBasedClusterManager.DBParam> dbParams = new ArrayList<FileBasedClusterManager.DBParam>(); dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1)); dbParams.add(new FileBasedClusterManager.DBParam("BizProfile", 1)); dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10)); dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128)); dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8)); dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1)); String[] nodesInfo = { "localhost:8900", "localhost:8901", "localhost:8902", "localhost:8903", "localhost:8904" }; String file = "/tmp/clusterView.json"; int replica = 0; // ClusterViewSerializer serializer = new ClusterViewSerializer(file); ClusterView view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, replica); view.setExternalView(new LinkedList<ZNRecord>()); ClusterViewSerializer.serialize(view, new File(file)); ClusterView restoredView = ClusterViewSerializer.deserialize(new File(file)); verifyClusterViews(view, restoredView); }
#vulnerable code @Test (groups = {"integrationTest"}) public void testFileBasedClusterManager() throws Exception { List<FileBasedClusterManager.DBParam> dbParams = new ArrayList<FileBasedClusterManager.DBParam>(); dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1)); dbParams.add(new FileBasedClusterManager.DBParam("BizProfile", 1)); dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10)); dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128)); dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8)); dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1)); String[] nodesInfo = { "localhost:8900", "localhost:8901", "localhost:8902", "localhost:8903", "localhost:8904" }; String file = "/tmp/clusterView.json"; int replica = 0; // ClusterViewSerializer serializer = new ClusterViewSerializer(file); ClusterView view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, replica); view.setExternalView(new LinkedList<ZNRecord>()); ClusterViewSerializer.serialize(view, new File(file)); ClusterView restoredView = ClusterViewSerializer.deserialize(new File(file)); VerifyClusterViews(view, restoredView); } #location 23 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void testZkClientMonitor() throws Exception { final String TEST_TAG = "test_monitor"; final String TEST_KEY = "test_key"; final String TEST_DATA = "testData"; final String TEST_ROOT = "/my_cluster/IDEALSTATES"; final String TEST_NODE = "/test_zkclient_monitor"; final String TEST_PATH = TEST_ROOT + TEST_NODE; ZkClient.Builder builder = new ZkClient.Builder(); builder.setZkServer(ZK_ADDR).setMonitorKey(TEST_KEY).setMonitorType(TEST_TAG) .setMonitorRootPathOnly(false); ZkClient zkClient = builder.build(); final long TEST_DATA_SIZE = zkClient.serialize(TEST_DATA, TEST_PATH).length; if (_zkClient.exists(TEST_PATH)) { _zkClient.delete(TEST_PATH); } if (!_zkClient.exists(TEST_ROOT)) { _zkClient.createPersistent(TEST_ROOT, true); } MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName name = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY); ObjectName rootname = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH, "Root"); ObjectName idealStatename = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH, "IdealStates"); Assert.assertTrue(beanServer.isRegistered(rootname)); Assert.assertTrue(beanServer.isRegistered(idealStatename)); // Test exists Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadLatencyGauge.Max"), 0); zkClient.exists(TEST_ROOT); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= 0); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadLatencyGauge.Max") >= 0); // Test create Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteLatencyGauge.Max"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteLatencyGauge.Max"), 0); zkClient.create(TEST_PATH, TEST_DATA, CreateMode.PERSISTENT); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), TEST_DATA_SIZE); long origWriteTotalLatencyCounter = (long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"); Assert.assertTrue(origWriteTotalLatencyCounter >= 0); Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteLatencyGauge.Max") >= 0); long origIdealStatesWriteTotalLatencyCounter = (long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"); Assert.assertTrue(origIdealStatesWriteTotalLatencyCounter >= 0); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteLatencyGauge.Max") >= 0); // Test read Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), 0); long origReadTotalLatencyCounter = (long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"); long origIdealStatesReadTotalLatencyCounter = (long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter"); Assert.assertEquals(origIdealStatesReadTotalLatencyCounter, 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadLatencyGauge.Max"), 0); zkClient.readData(TEST_PATH, new Stat()); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 2); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= origReadTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter") >= origIdealStatesReadTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadLatencyGauge.Max") >= 0); zkClient.getChildren(TEST_PATH); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 3); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); zkClient.getStat(TEST_PATH); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 4); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 3); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); zkClient.readDataAndStat(TEST_PATH, new Stat(), true); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 5); ZkAsyncCallbacks.ExistsCallbackHandler callbackHandler = new ZkAsyncCallbacks.ExistsCallbackHandler(); zkClient.asyncExists(TEST_PATH, callbackHandler); callbackHandler.waitForSuccess(); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 6); // Test write zkClient.writeData(TEST_PATH, TEST_DATA); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), TEST_DATA_SIZE * 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), TEST_DATA_SIZE * 2); Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter") >= origWriteTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter") >= origIdealStatesWriteTotalLatencyCounter); // Test data change count final Lock lock = new ReentrantLock(); final Condition callbackFinish = lock.newCondition(); zkClient.subscribeDataChanges(TEST_PATH, new IZkDataListener() { @Override public void handleDataChange(String dataPath, Object data) throws Exception { } @Override public void handleDataDeleted(String dataPath) throws Exception { lock.lock(); try { callbackFinish.signal(); } finally { lock.unlock(); } } }); lock.lock(); _zkClient.delete(TEST_PATH); Assert.assertTrue(callbackFinish.await(10, TimeUnit.SECONDS)); Assert.assertEquals((long) beanServer.getAttribute(name, "DataChangeEventCounter"), 1); }
#vulnerable code @Test public void testZkClientMonitor() throws Exception { final String TEST_TAG = "test_monitor"; final String TEST_KEY = "test_key"; final String TEST_DATA = "testData"; final String TEST_ROOT = "/my_cluster/IDEALSTATES"; final String TEST_NODE = "/test_zkclient_monitor"; final String TEST_PATH = TEST_ROOT + TEST_NODE; ZkClient zkClient = new ZkClient(ZK_ADDR, TEST_TAG, TEST_KEY); final long TEST_DATA_SIZE = zkClient.serialize(TEST_DATA, TEST_PATH).length; if (_zkClient.exists(TEST_PATH)) { _zkClient.delete(TEST_PATH); } if (!_zkClient.exists(TEST_ROOT)) { _zkClient.createPersistent(TEST_ROOT, true); } MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName name = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY); ObjectName rootname = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH, "Root"); ObjectName idealStatename = MBeanRegistrar .buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE, TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH, "IdealStates"); Assert.assertTrue(beanServer.isRegistered(rootname)); Assert.assertTrue(beanServer.isRegistered(idealStatename)); // Test exists Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadMaxLatencyGauge"), 0); zkClient.exists(TEST_ROOT); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= 0); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadMaxLatencyGauge") >= 0); // Test create Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteMaxLatencyGauge"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteMaxLatencyGauge"), 0); zkClient.create(TEST_PATH, TEST_DATA, CreateMode.PERSISTENT); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), TEST_DATA_SIZE); long origWriteTotalLatencyCounter = (long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"); Assert.assertTrue(origWriteTotalLatencyCounter >= 0); Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteMaxLatencyGauge") >= 0); long origIdealStatesWriteTotalLatencyCounter = (long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"); Assert.assertTrue(origIdealStatesWriteTotalLatencyCounter >= 0); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteMaxLatencyGauge") >= 0); // Test read Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), 0); long origReadTotalLatencyCounter = (long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"); long origIdealStatesReadTotalLatencyCounter = (long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter"); Assert.assertEquals(origIdealStatesReadTotalLatencyCounter, 0); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadMaxLatencyGauge"), 0); zkClient.readData(TEST_PATH, new Stat()); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 2); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 1); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= origReadTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter") >= origIdealStatesReadTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadMaxLatencyGauge") >= 0); zkClient.getChildren(TEST_PATH); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 3); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); zkClient.getStat(TEST_PATH); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 4); Assert .assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 3); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), TEST_DATA_SIZE); zkClient.readDataAndStat(TEST_PATH, new Stat(), true); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 5); ZkAsyncCallbacks.ExistsCallbackHandler callbackHandler = new ZkAsyncCallbacks.ExistsCallbackHandler(); zkClient.asyncExists(TEST_PATH, callbackHandler); callbackHandler.waitForSuccess(); Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 6); // Test write zkClient.writeData(TEST_PATH, TEST_DATA); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), TEST_DATA_SIZE * 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 2); Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), TEST_DATA_SIZE * 2); Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter") >= origWriteTotalLatencyCounter); Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter") >= origIdealStatesWriteTotalLatencyCounter); // Test data change count final Lock lock = new ReentrantLock(); final Condition callbackFinish = lock.newCondition(); zkClient.subscribeDataChanges(TEST_PATH, new IZkDataListener() { @Override public void handleDataChange(String dataPath, Object data) throws Exception { } @Override public void handleDataDeleted(String dataPath) throws Exception { lock.lock(); try { callbackFinish.signal(); } finally { lock.unlock(); } } }); lock.lock(); _zkClient.delete(TEST_PATH); Assert.assertTrue(callbackFinish.await(10, TimeUnit.SECONDS)); Assert.assertEquals((long) beanServer.getAttribute(name, "DataChangeEventCounter"), 1); } #location 15 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Override public void disconnect() { if (_zkclient == null || _zkclient.isClosed()) { LOG.info("instanceName: " + _instanceName + " already disconnected"); return; } LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName); try { /** * stop all timer tasks */ stopTimerTasks(); /** * shutdown thread pool first to avoid reset() being invoked in the middle of state * transition */ _messagingService.getExecutor().shutdown(); if (!cleanupCallbackHandlers()) { LOG.warn( "The callback handler cleanup has been cleanly done. " + "Some callback handlers might not be reset properly. " + "Continue to finish the other Helix Mananger disconnect tasks."); } } finally { GenericHelixController controller = _controller; if (controller != null) { try { controller.shutdown(); } catch (InterruptedException e) { LOG.info("Interrupted shutting down GenericHelixController", e); } } for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) { callbackMonitor.unregister(); } _helixPropertyStore = null; synchronized (this) { if (_controller != null) { _controller = null; _leaderElectionHandler = null; } if (_participantManager != null) { _participantManager = null; } if (_zkclient != null) { _zkclient.close(); } } _sessionStartTime = null; LOG.info("Cluster manager: " + _instanceName + " disconnected"); } }
#vulnerable code @Override public void disconnect() { if (_zkclient == null || _zkclient.isClosed()) { LOG.info("instanceName: " + _instanceName + " already disconnected"); return; } LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName); try { /** * stop all timer tasks */ stopTimerTasks(); /** * shutdown thread pool first to avoid reset() being invoked in the middle of state * transition */ _messagingService.getExecutor().shutdown(); // TODO reset user defined handlers only // TODO Fix the issue that when connection disconnected, reset handlers will be blocked. -- JJ // This is because reset logic contains ZK operations. resetHandlers(true); if (_leaderElectionHandler != null) { _leaderElectionHandler.reset(true); } } finally { GenericHelixController controller = _controller; if (controller != null) { try { controller.shutdown(); } catch (InterruptedException e) { LOG.info("Interrupted shutting down GenericHelixController", e); } } ParticipantManager participantManager = _participantManager; if (participantManager != null) { participantManager.disconnect(); } for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) { callbackMonitor.unregister(); } _helixPropertyStore = null; synchronized (this) { if (_controller != null) { _controller = null; _leaderElectionHandler = null; } if (_participantManager != null) { _participantManager = null; } if (_zkclient != null) { _zkclient.close(); } } _sessionStartTime = null; LOG.info("Cluster manager: " + _instanceName + " disconnected"); } } #location 43 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public void setRequestedState(String partitionName, String state) { setProperty(partitionName, CurrentStateProperty.REQUESTED_STATE, state); }
#vulnerable code public void setRequestedState(String partitionName, String state) { Map<String, Map<String, String>> mapFields = _record.getMapFields(); if (mapFields.get(partitionName) == null) { mapFields.put(partitionName, new TreeMap<String, String>()); } mapFields.get(partitionName).put(CurrentStateProperty.REQUESTED_STATE.name(), state); } #location 6 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void testInvocationAnnotated() throws Exception { System.out.println("TestCMTaskHandler.testInvocationAnnotated()"); Message message = new Message(MessageType.STATE_TRANSITION); message.setSrcName("cm-instance-0"); message.setTgtSessionId("1234"); message.setFromState("Offline"); message.setToState("Slave"); message.setStateUnitKey("Teststateunitkey"); message.setId("Some unique id"); message.setMsgId("Some unique message id"); MockStateModelAnnotated stateModel = new MockStateModelAnnotated(); NotificationContext context; context = new NotificationContext(new MockManager()); CMTaskHandler handler; CMStateTransitionHandler stHandler = new CMStateTransitionHandler(stateModel); handler = new CMTaskHandler(message, context, stHandler, null); handler.call(); AssertJUnit.assertTrue(stateModel.stateModelInvoked); }
#vulnerable code @Test public void testInvocationAnnotated() throws Exception { System.out.println("TestCMTaskHandler.testInvocationAnnotated()"); Message message = new Message(MessageType.STATE_TRANSITION); message.setSrcName("cm-instance-0"); message.setTgtSessionId("1234"); message.setFromState("Offline"); message.setToState("Slave"); message.setStateUnitKey("Teststateunitkey"); message.setId("Some unique id"); message.setMsgId("Some unique message id"); MockStateModelAnnotated stateModel = new MockStateModelAnnotated(); NotificationContext context; context = new NotificationContext(new MockManager()); CMTaskHandler handler; handler = new CMTaskHandler(message, context, null, null); handler.call(); AssertJUnit.assertTrue(stateModel.stateModelInvoked); } #location 19 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Override public void handleDataDeleted(String dataPath) { if (_zkClientForRoutingDataListener == null || _zkClientForRoutingDataListener.isClosed()) { return; } // Resubscribe _zkClientForRoutingDataListener.unsubscribeAll(); _zkClientForRoutingDataListener.subscribeRoutingDataChanges(this, this); resetZkResources(); }
#vulnerable code @Override public void handleDataDeleted(String dataPath) { if (_zkClientForListener == null || _zkClientForListener.isClosed()) { return; } // Resubscribe _zkClientForListener.unsubscribeAll(); _zkClientForListener.subscribeRoutingDataChanges(this, this); resetZkResources(); } #location 8 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Test public void testSimpleCS() { // setup resource Map<String, Resource> resourceMap = getResourceMap(); setupLiveInstances(5); event.addAttribute(AttributeName.RESOURCES.name(), resourceMap); event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap); CurrentStateComputationStage stage = new CurrentStateComputationStage(); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE.name()); AssertJUnit.assertEquals( output1.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(), 0); // Add a state transition messages Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1"); message.setFromState("OFFLINE"); message.setToState("SLAVE"); message.setResourceName("testResourceName"); message.setPartitionName("testResourceName_1"); message.setTgtName("localhost_3"); message.setTgtSessionId("session_3"); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE.name()); String pendingState = output2.getPendingState("testResourceName", new Partition("testResourceName_1"), "localhost_3").getToState(); AssertJUnit.assertEquals(pendingState, "SLAVE"); ZNRecord record1 = new ZNRecord("testResourceName"); // Add a current state that matches sessionId and one that does not match CurrentState stateWithLiveSession = new CurrentState(record1); stateWithLiveSession.setSessionId("session_3"); stateWithLiveSession.setStateModelDefRef("MasterSlave"); stateWithLiveSession.setState("testResourceName_1", "OFFLINE"); ZNRecord record2 = new ZNRecord("testResourceName"); CurrentState stateWithDeadSession = new CurrentState(record2); stateWithDeadSession.setSessionId("session_dead"); stateWithDeadSession.setStateModelDefRef("MasterSlave"); stateWithDeadSession.setState("testResourceName_1", "MASTER"); accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"), stateWithLiveSession); accessor.setProperty( keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"), stateWithDeadSession); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE.name()); String currentState = output3.getCurrentState("testResourceName", new Partition("testResourceName_1"), "localhost_3"); AssertJUnit.assertEquals(currentState, "OFFLINE"); }
#vulnerable code @Test public void testSimpleCS() { // setup resource Map<String, Resource> resourceMap = getResourceMap(); setupLiveInstances(5); event.addAttribute(AttributeName.RESOURCES.name(), resourceMap); CurrentStateComputationStage stage = new CurrentStateComputationStage(); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE.name()); AssertJUnit.assertEquals( output1.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(), 0); // Add a state transition messages Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1"); message.setFromState("OFFLINE"); message.setToState("SLAVE"); message.setResourceName("testResourceName"); message.setPartitionName("testResourceName_1"); message.setTgtName("localhost_3"); message.setTgtSessionId("session_3"); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE.name()); String pendingState = output2.getPendingState("testResourceName", new Partition("testResourceName_1"), "localhost_3").getToState(); AssertJUnit.assertEquals(pendingState, "SLAVE"); ZNRecord record1 = new ZNRecord("testResourceName"); // Add a current state that matches sessionId and one that does not match CurrentState stateWithLiveSession = new CurrentState(record1); stateWithLiveSession.setSessionId("session_3"); stateWithLiveSession.setStateModelDefRef("MasterSlave"); stateWithLiveSession.setState("testResourceName_1", "OFFLINE"); ZNRecord record2 = new ZNRecord("testResourceName"); CurrentState stateWithDeadSession = new CurrentState(record2); stateWithDeadSession.setSessionId("session_dead"); stateWithDeadSession.setStateModelDefRef("MasterSlave"); stateWithDeadSession.setState("testResourceName_1", "MASTER"); accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"), stateWithLiveSession); accessor.setProperty( keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"), stateWithDeadSession); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE.name()); String currentState = output3.getCurrentState("testResourceName", new Partition("testResourceName_1"), "localhost_3"); AssertJUnit.assertEquals(currentState, "OFFLINE"); } #location 58 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Override public void disconnect() { if (_zkclient == null || _zkclient.isClosed()) { LOG.info("instanceName: " + _instanceName + " already disconnected"); return; } LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName); try { /** * stop all timer tasks */ stopTimerTasks(); /** * shutdown thread pool first to avoid reset() being invoked in the middle of state * transition */ _messagingService.getExecutor().shutdown(); if (!cleanupCallbackHandlers()) { LOG.warn( "The callback handler cleanup has been cleanly done. " + "Some callback handlers might not be reset properly. " + "Continue to finish the other Helix Mananger disconnect tasks."); } } finally { GenericHelixController controller = _controller; if (controller != null) { try { controller.shutdown(); } catch (InterruptedException e) { LOG.info("Interrupted shutting down GenericHelixController", e); } } for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) { callbackMonitor.unregister(); } _helixPropertyStore = null; synchronized (this) { if (_controller != null) { _controller = null; _leaderElectionHandler = null; } if (_participantManager != null) { _participantManager = null; } if (_zkclient != null) { _zkclient.close(); } } _sessionStartTime = null; LOG.info("Cluster manager: " + _instanceName + " disconnected"); } }
#vulnerable code @Override public void disconnect() { if (_zkclient == null || _zkclient.isClosed()) { LOG.info("instanceName: " + _instanceName + " already disconnected"); return; } LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName); try { /** * stop all timer tasks */ stopTimerTasks(); /** * shutdown thread pool first to avoid reset() being invoked in the middle of state * transition */ _messagingService.getExecutor().shutdown(); // TODO reset user defined handlers only // TODO Fix the issue that when connection disconnected, reset handlers will be blocked. -- JJ // This is because reset logic contains ZK operations. resetHandlers(true); if (_leaderElectionHandler != null) { _leaderElectionHandler.reset(true); } } finally { GenericHelixController controller = _controller; if (controller != null) { try { controller.shutdown(); } catch (InterruptedException e) { LOG.info("Interrupted shutting down GenericHelixController", e); } } ParticipantManager participantManager = _participantManager; if (participantManager != null) { participantManager.disconnect(); } for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) { callbackMonitor.unregister(); } _helixPropertyStore = null; synchronized (this) { if (_controller != null) { _controller = null; _leaderElectionHandler = null; } if (_participantManager != null) { _participantManager = null; } if (_zkclient != null) { _zkclient.close(); } } _sessionStartTime = null; LOG.info("Cluster manager: " + _instanceName + " disconnected"); } } #location 28 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public void testSimpleCS() { // setup resource group Map<String, ResourceGroup> resourceGroupMap = getResourceGroupMap(); setupLiveInstances(5); event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(), resourceGroupMap); CurrentStateComputationStage stage = new CurrentStateComputationStage(); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); Assert.assertEquals( output1.getCurrentStateMap("testResourceGroupName", new ResourceKey("testResourceGroupName_0")).size(), 0); // Add a state transition messages Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1"); message.setFromState("OFFLINE"); message.setToState("SLAVE"); message.setStateUnitGroup("testResourceGroupName"); message.setStateUnitKey("testResourceGroupName_1"); message.setTgtName("localhost_3"); message.setTgtSessionId("session_3"); accessor.setProperty(PropertyType.MESSAGES, message.getRecord(), "localhost_" + 3, message.getId()); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); String pendingState = output2.getPendingState("testResourceGroupName", new ResourceKey("testResourceGroupName_1"), "localhost_3"); Assert.assertEquals(pendingState, "SLAVE"); ZNRecord record1 = new ZNRecord("testResourceGroupName"); // Add a current state that matches sessionId and one that does not match CurrentState stateWithLiveSession = new CurrentState(record1); stateWithLiveSession.setSessionId("session_3"); stateWithLiveSession.setStateModelDefRef("MasterSlave"); stateWithLiveSession.setState("testResourceGroupName_1", "OFFLINE"); ZNRecord record2 = new ZNRecord("testResourceGroupName"); CurrentState stateWithDeadSession = new CurrentState(record2); stateWithDeadSession.setSessionId("session_dead"); stateWithDeadSession.setStateModelDefRef("MasterSlave"); stateWithDeadSession.setState("testResourceGroupName_1", "MASTER"); accessor.setProperty(PropertyType.CURRENTSTATES, stateWithLiveSession.getRecord(), "localhost_3", "session_3", "testResourceGroupName"); accessor.setProperty(PropertyType.CURRENTSTATES, stateWithDeadSession.getRecord(), "localhost_3", "session_dead", "testResourceGroupName"); runStage(event, new ReadClusterDataStage()); runStage(event, stage); CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); String currentState = output3.getCurrentState("testResourceGroupName", new ResourceKey("testResourceGroupName_1"), "localhost_3"); Assert.assertEquals(currentState, "OFFLINE"); }
#vulnerable code public void testSimpleCS() { // setup resource group Map<String, ResourceGroup> resourceGroupMap = getResourceGroupMap(); setupLiveInstances(5); event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(), resourceGroupMap); CurrentStateComputationStage stage = new CurrentStateComputationStage(); runStage(event, stage); CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); Assert.assertEquals( output1.getCurrentStateMap("testResourceGroupName", new ResourceKey("testResourceGroupName_0")).size(), 0); // Add a state transition messages Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1"); message.setFromState("OFFLINE"); message.setToState("SLAVE"); message.setStateUnitGroup("testResourceGroupName"); message.setStateUnitKey("testResourceGroupName_1"); message.setTgtName("localhost_3"); message.setTgtSessionId("session_3"); accessor.setProperty(PropertyType.MESSAGES, message.getRecord(), "localhost_" + 3, message.getId()); runStage(event, stage); CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); String pendingState = output2.getPendingState("testResourceGroupName", new ResourceKey("testResourceGroupName_1"), "localhost_3"); Assert.assertEquals(pendingState, "SLAVE"); ZNRecord record1 = new ZNRecord("testResourceGroupName"); // Add a current state that matches sessionId and one that does not match CurrentState stateWithLiveSession = new CurrentState(record1); stateWithLiveSession.setSessionId("session_3"); stateWithLiveSession.setStateModelDefRef("MasterSlave"); stateWithLiveSession.setState("testResourceGroupName_1", "OFFLINE"); ZNRecord record2 = new ZNRecord("testResourceGroupName"); CurrentState stateWithDeadSession = new CurrentState(record2); stateWithDeadSession.setSessionId("session_dead"); stateWithDeadSession.setStateModelDefRef("MasterSlave"); stateWithDeadSession.setState("testResourceGroupName_1", "MASTER"); accessor.setProperty(PropertyType.CURRENTSTATES, stateWithLiveSession.getRecord(), "localhost_3", "session_3", "testResourceGroupName"); accessor.setProperty(PropertyType.CURRENTSTATES, stateWithDeadSession.getRecord(), "localhost_3", "session_dead", "testResourceGroupName"); runStage(event, stage); CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE .toString()); String currentState = output3.getCurrentState("testResourceGroupName", new ResourceKey("testResourceGroupName_1"), "localhost_3"); Assert.assertEquals(currentState, "OFFLINE"); } #location 56 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public void download(String zkPath, String fsPath) throws Exception { List<String> children = client.getChildren(zkPath); if (children != null && children.size() > 0) { new File(fsPath).mkdirs(); for (String child : children) { String childPath = zkPath.equals("/") ? "/" + child : zkPath + "/" + child; download(childPath, fsPath + "/" + child); } } else { System.out .println("Saving " + zkPath + " to " + new File(fsPath + suffix).getCanonicalPath()); OutputStream out = new FileOutputStream(fsPath + suffix); Object readData = client.readData(zkPath); if (readData != null) { out.write((byte[]) readData); } out.close(); } }
#vulnerable code public void download(String zkPath, String fsPath) throws Exception { List<String> children = client.getChildren(zkPath); if (children != null && children.size() > 0) { new File(fsPath).mkdirs(); for (String child : children) { String childPath = zkPath.equals("/")? "/" + child : zkPath + "/" + child; download(childPath, fsPath + "/" + child); } } else { System.out.println("Saving " + zkPath + " to " + new File(fsPath + suffix).getCanonicalPath()); FileWriter fileWriter = new FileWriter(fsPath + suffix); Object readData = client.readData(zkPath); if (readData != null) { fileWriter.write((String) readData); } fileWriter.close(); } } #location 12 #vulnerability type RESOURCE_LEAK
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code void startRebalancingTimer(long period, HelixManager manager) { if (period != _timerPeriod) { logger.info("Controller starting timer at period " + period); if (_rebalanceTimer != null) { _rebalanceTimer.cancel(); } _rebalanceTimer = new Timer(true); _timerPeriod = period; _rebalanceTimer .scheduleAtFixedRate(new RebalanceTask(manager), _timerPeriod, _timerPeriod); } else { logger.info("Controller already has timer at period " + _timerPeriod); } }
#vulnerable code void stopRebalancingTimer() { if (_rebalanceTimer != null) { _rebalanceTimer.cancel(); _rebalanceTimer = null; } _timerPeriod = Integer.MAX_VALUE; } #location 6 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code protected void handleNewSession() { boolean isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS); while (!isConnected) { logger.error("Could NOT connect to zk server in " + CONNECTIONTIMEOUT + "ms. zkServer: " + _zkConnectString + ", expiredSessionId: " + _sessionId + ", clusterName: " + _clusterName); isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS); } ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection()); synchronized (this) { _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId()); } _baseDataAccessor.reset(); // reset all handlers so they have a chance to unsubscribe zk changes from zkclient // abandon all callback-handlers added in expired session resetHandlers(); logger.info("Handling new session, session id:" + _sessionId + ", instance:" + _instanceName + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName); logger.info(zkConnection.getZookeeper()); if (!ZKUtil.isClusterSetup(_clusterName, _zkClient)) { throw new HelixException("Initial cluster structure is not set up for cluster:" + _clusterName); } // Read cluster config and see if instance can auto join the cluster boolean autoJoin = false; try { ConfigScope scope = new ConfigScopeBuilder().forCluster(getClusterName()) .build(); autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN)); logger.info("Auto joining " + _clusterName +" is true"); } catch(Exception e) { } if (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType)) { if(!autoJoin) { throw new HelixException("Initial cluster structure is not set up for instance:" + _instanceName + " instanceType:" + _instanceType); } else { logger.info("Auto joining instance " + _instanceName); InstanceConfig instanceConfig = new InstanceConfig(_instanceName); String hostName = _instanceName; String port = ""; int lastPos = _instanceName.lastIndexOf("_"); if (lastPos > 0) { hostName = _instanceName.substring(0, lastPos); port = _instanceName.substring(lastPos + 1); } instanceConfig.setHostName(hostName); instanceConfig.setPort(port); instanceConfig.setInstanceEnabled(true); getClusterManagmentTool().addInstance(_clusterName, instanceConfig); } } if (_instanceType == InstanceType.PARTICIPANT || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) { handleNewSessionAsParticipant(); } if (_instanceType == InstanceType.CONTROLLER || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) { addControllerMessageListener(_messagingService.getExecutor()); MessageHandlerFactory defaultControllerMsgHandlerFactory = new DefaultControllerMessageHandlerFactory(); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(), defaultControllerMsgHandlerFactory); MessageHandlerFactory defaultSchedulerMsgHandlerFactory = new DefaultSchedulerMessageHandlerFactory(this); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(), defaultSchedulerMsgHandlerFactory); MessageHandlerFactory defaultParticipantErrorMessageHandlerFactory = new DefaultParticipantErrorMessageHandlerFactory(this); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(), defaultParticipantErrorMessageHandlerFactory); if (_leaderElectionHandler != null) { _leaderElectionHandler.reset(); _leaderElectionHandler.init(); } else { _leaderElectionHandler = createCallBackHandler(new Builder(_clusterName).controller(), new DistClusterControllerElection(_zkConnectString), new EventType[] { EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated }, ChangeType.CONTROLLER); } } if (_instanceType == InstanceType.PARTICIPANT || _instanceType == InstanceType.CONTROLLER_PARTICIPANT || (_instanceType == InstanceType.CONTROLLER && isLeader())) { initHandlers(); } }
#vulnerable code protected void handleNewSession() { boolean isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS); while (!isConnected) { logger.error("Could NOT connect to zk server in " + CONNECTIONTIMEOUT + "ms. zkServer: " + _zkConnectString + ", expiredSessionId: " + _sessionId + ", clusterName: " + _clusterName); isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS); } ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection()); synchronized (this) { _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId()); } _baseDataAccessor.reset(); // reset all handlers so they have a chance to unsubscribe zk changes from zkclient // abandon all callback-handlers added in expired session resetHandlers(); _handlers = new ArrayList<CallbackHandler>(); logger.info("Handling new session, session id:" + _sessionId + ", instance:" + _instanceName + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName); logger.info(zkConnection.getZookeeper()); if (!ZKUtil.isClusterSetup(_clusterName, _zkClient)) { throw new HelixException("Initial cluster structure is not set up for cluster:" + _clusterName); } // Read cluster config and see if instance can auto join the cluster boolean autoJoin = false; try { ConfigScope scope = new ConfigScopeBuilder().forCluster(getClusterName()) .build(); autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN)); logger.info("Auto joining " + _clusterName +" is true"); } catch(Exception e) { } if (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType)) { if(!autoJoin) { throw new HelixException("Initial cluster structure is not set up for instance:" + _instanceName + " instanceType:" + _instanceType); } else { logger.info("Auto joining instance " + _instanceName); InstanceConfig instanceConfig = new InstanceConfig(_instanceName); String hostName = _instanceName; String port = ""; int lastPos = _instanceName.lastIndexOf("_"); if (lastPos > 0) { hostName = _instanceName.substring(0, lastPos); port = _instanceName.substring(lastPos + 1); } instanceConfig.setHostName(hostName); instanceConfig.setPort(port); instanceConfig.setInstanceEnabled(true); getClusterManagmentTool().addInstance(_clusterName, instanceConfig); } } if (_instanceType == InstanceType.PARTICIPANT || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) { handleNewSessionAsParticipant(); } if (_instanceType == InstanceType.CONTROLLER || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) { addControllerMessageListener(_messagingService.getExecutor()); MessageHandlerFactory defaultControllerMsgHandlerFactory = new DefaultControllerMessageHandlerFactory(); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(), defaultControllerMsgHandlerFactory); MessageHandlerFactory defaultSchedulerMsgHandlerFactory = new DefaultSchedulerMessageHandlerFactory(this); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(), defaultSchedulerMsgHandlerFactory); MessageHandlerFactory defaultParticipantErrorMessageHandlerFactory = new DefaultParticipantErrorMessageHandlerFactory(this); _messagingService.getExecutor() .registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(), defaultParticipantErrorMessageHandlerFactory); // create a new leader-election handler for a new session if (_leaderElectionHandler != null) { _leaderElectionHandler.reset(); } _leaderElectionHandler = createCallBackHandler(new Builder(_clusterName).controller(), new DistClusterControllerElection(_zkConnectString), new EventType[] { EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated }, ChangeType.CONTROLLER); } if (_instanceType == InstanceType.PARTICIPANT || _instanceType == InstanceType.CONTROLLER_PARTICIPANT || (_instanceType == InstanceType.CONTROLLER && isLeader())) { initHandlers(); } } #location 23 #vulnerability type THREAD_SAFETY_VIOLATION
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code public void setInfo(String partitionName, String info) { setProperty(partitionName, CurrentStateProperty.INFO, info); }
#vulnerable code public void setInfo(String partitionName, String info) { Map<String, Map<String, String>> mapFields = _record.getMapFields(); if (mapFields.get(partitionName) == null) { mapFields.put(partitionName, new TreeMap<String, String>()); } mapFields.get(partitionName).put(CurrentStateProperty.INFO.name(), info); } #location 6 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.
#fixed code @Override public Object deserialize(byte[] bytes) throws ZkMarshallingError { if (bytes == null || bytes.length == 0) { LOG.error("ZNode is empty."); return null; } ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ZNRecord record = null; String id = null; Map<String, String> simpleFields = Maps.newHashMap(); Map<String, List<String>> listFields = Maps.newHashMap(); Map<String, Map<String, String>> mapFields = Maps.newHashMap(); byte[] rawPayload = null; try { JsonFactory f = new JsonFactory(); JsonParser jp = f.createJsonParser(bais); jp.nextToken(); // will return JsonToken.START_OBJECT (verify?) while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY if ("id".equals(fieldname)) { // contains an object id = jp.getText(); } else if ("simpleFields".equals(fieldname)) { while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); jp.nextToken(); // move to value simpleFields.put(key, jp.getText()); } } else if ("mapFields".equals(fieldname)) { // user.setVerified(jp.getCurrentToken() == JsonToken.VALUE_TRUE); while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); mapFields.put(key, new TreeMap<String, String>()); jp.nextToken(); // move to value while (jp.nextToken() != JsonToken.END_OBJECT) { String mapKey = jp.getCurrentName(); jp.nextToken(); // move to value mapFields.get(key).put(mapKey, jp.getText()); } } } else if ("listFields".equals(fieldname)) { // user.setUserImage(jp.getBinaryValue()); while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); listFields.put(key, new ArrayList<String>()); jp.nextToken(); // move to value while (jp.nextToken() != JsonToken.END_ARRAY) { listFields.get(key).add(jp.getText()); } } } else if ("rawPayload".equals(fieldname)) { rawPayload = Base64.decode(jp.getText()); } else { throw new IllegalStateException("Unrecognized field '" + fieldname + "'!"); } } jp.close(); // ensure resources get cleaned up timely and properly if (id == null) { throw new IllegalStateException("ZNRecord id field is required!"); } record = new ZNRecord(id); record.setSimpleFields(simpleFields); record.setListFields(listFields); record.setMapFields(mapFields); record.setRawPayload(rawPayload); } catch (Exception e) { LOG.error("Exception during deserialization of bytes: " + new String(bytes), e); } return record; }
#vulnerable code @Override public Object deserialize(byte[] bytes) throws ZkMarshallingError { if (bytes == null || bytes.length == 0) { LOG.error("ZNode is empty."); return null; } ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ZNRecord record = null; try { JsonFactory f = new JsonFactory(); JsonParser jp = f.createJsonParser(bais); jp.nextToken(); // will return JsonToken.START_OBJECT (verify?) while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY if ("id".equals(fieldname)) { // contains an object record = new ZNRecord(jp.getText()); } else if ("simpleFields".equals(fieldname)) { while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); jp.nextToken(); // move to value record.setSimpleField(key, jp.getText()); } } else if ("mapFields".equals(fieldname)) { // user.setVerified(jp.getCurrentToken() == JsonToken.VALUE_TRUE); while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); record.setMapField(key, new TreeMap<String, String>()); jp.nextToken(); // move to value while (jp.nextToken() != JsonToken.END_OBJECT) { String mapKey = jp.getCurrentName(); jp.nextToken(); // move to value record.getMapField(key).put(mapKey, jp.getText()); } } } else if ("listFields".equals(fieldname)) { // user.setUserImage(jp.getBinaryValue()); while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); record.setListField(key, new ArrayList<String>()); jp.nextToken(); // move to value while (jp.nextToken() != JsonToken.END_ARRAY) { record.getListField(key).add(jp.getText()); } } } else if ("rawPayload".equals(fieldname)) { record.setRawPayload(Base64.decode(jp.getText())); } else { throw new IllegalStateException("Unrecognized field '" + fieldname + "'!"); } } jp.close(); // ensure resources get cleaned up timely and properly } catch (Exception e) { LOG.error("Exception during deserialization of bytes: " + new String(bytes), e); } return record; } #location 55 #vulnerability type NULL_DEREFERENCE
Below is the vulnerable code, please generate the patch based on the following information.