output stringlengths 64 73.2k | input stringlengths 208 73.3k | instruction stringclasses 1
value |
|---|---|---|
#fixed code
public void processMessage(NulsMessage message) throws IOException {
//todo
if (true) {
try {
System.out.println("------receive message:" + Hex.encode(message.serialize()));
} catch (IOException e) {
e.pr... | #vulnerable code
public void processMessage(NulsMessage message) throws IOException {
if (message.getHeader().getHeadType() == NulsMessageHeader.EVENT_MESSAGE) {
try {
System.out.println("------receive message:" + Hex.encode(message.serialize()));
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean downloadedBlock(String nodeId, Block block) {
System.out.println("downloaded:" + block.getHeader().getHeight());
NodeDownloadingStatus status = nodeStatusMap.get(nodeId);
if (null == status) {
return false;
}
... | #vulnerable code
public boolean downloadedBlock(String nodeId, Block block) {
System.out.println("downloaded:"+block.getHeader().getHeight());
NodeDownloadingStatus status = nodeStatusMap.get(nodeId);
if (null == status) {
return false;
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void onEvent(DisruptorData<ProcessData<E>> processDataDisruptorMessage, long l, boolean b) {
try {
BaseMessage message = processDataDisruptorMessage.getData().getData();
if (null == message || message.getHeader() == null) {... | #vulnerable code
@Override
public void onEvent(DisruptorData<ProcessData<E>> processDataDisruptorMessage, long l, boolean b) {
try {
BaseMessage message = processDataDisruptorMessage.getData().getData();
if (null == message || message.getHeader() == n... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public ValidateResult validate(Block block) {
if (block.getHeader().getTxCount() != block.getTxs().size()) {
return ValidateResult.getFailedResult("txCount is wrong!");
}
int count = 0;
List<Transaction> txList = new A... | #vulnerable code
@Override
public ValidateResult validate(Block block) {
if (block.getHeader().getTxCount() != block.getTxs().size()) {
return ValidateResult.getFailedResult("txCount is wrong!");
}
int count = 0;
for (Transaction tx : bloc... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private boolean verifyBaseTx(Block block, MeetingRound currentRound, MeetingMember member) {
List<Transaction> txs = block.getTxs();
Transaction tx = txs.get(0);
if (tx.getType() != TransactionConstant.TX_TYPE_COIN_BASE) {
BlockLog.debug("C... | #vulnerable code
private boolean verifyBaseTx(Block block, MeetingRound currentRound, MeetingMember member) {
if(5176 == block.getHeader().getHeight()) {
System.out.println("in the bug");
}
List<Transaction> txs = block.getTxs();
Transaction t... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
@DbSession
public void save(CoinData coinData, Transaction tx) throws NulsException {
UtxoData utxoData = (UtxoData) coinData;
List<UtxoInputPo> inputPoList = new ArrayList<>();
List<UtxoOutput> spends = new ArrayList<>();
Li... | #vulnerable code
@Override
@DbSession
public void save(CoinData coinData, Transaction tx) throws NulsException {
UtxoData utxoData = (UtxoData) coinData;
List<UtxoInputPo> inputPoList = new ArrayList<>();
List<UtxoOutput> spends = new ArrayList<>();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean addBlockHashResponse(String nodeId, BlockHashResponse response) {
if (this.nodeIdList == null || !this.nodeIdList.contains(nodeId)) {
return false;
}
if (!requesting) {
return false;
}
if (response... | #vulnerable code
public boolean addBlockHashResponse(String nodeId, BlockHashResponse response) {
if (this.nodeIdList == null || !this.nodeIdList.contains(nodeId)) {
return false;
}
if (!requesting) {
return false;
}
if (re... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
@DbSession
public boolean saveBlock(Block block) throws IOException {
BlockLog.debug("save block height:" + block.getHeader().getHeight() + ", preHash:" + block.getHeader().getPreHash() + " , hash:" + block.getHeader().getHash() + ", address:" + Addr... | #vulnerable code
@Override
@DbSession
public boolean saveBlock(Block block) throws IOException {
BlockLog.debug("save block height:" + block.getHeader().getHeight() + ", preHash:" + block.getHeader().getPreHash() + " , hash:" + block.getHeader().getHash() + ", address:" ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.setHeader(byteBuffer.readNulsData(new EventHeader()));
// version = new NulsVersion(byteBuffer.readShort());
bestBlockHeight = byteBuffer.readVarInt();
bes... | #vulnerable code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.setHeader(byteBuffer.readNulsData(new EventHeader()));
// version = new NulsVersion(byteBuffer.readShort());
bestBlockHeight = byteBuffer.readVarInt();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void requestTxGroup(NulsDigestData blockHash, String nodeId) {
GetTxGroupRequest request = new GetTxGroupRequest();
GetTxGroupParam data = new GetTxGroupParam();
data.setBlockHash(blockHash);
List<NulsDigestData> txHashList = new ArrayLi... | #vulnerable code
public void requestTxGroup(NulsDigestData blockHash, String nodeId) {
GetTxGroupRequest request = new GetTxGroupRequest();
GetTxGroupParam data = new GetTxGroupParam();
data.setBlockHash(blockHash);
List<NulsDigestData> txHashList = new A... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public PocMeetingRound getRound(long preRoundIndex, long roundIndex, boolean needPreRound) {
PocMeetingRound round = ROUND_MAP.get(roundIndex);
Block preRoundFirstBlock = null;
BlockRoundData preRoundData = null;
if (null == round) {
... | #vulnerable code
public PocMeetingRound getRound(long preRoundIndex, long roundIndex, boolean needPreRound) {
PocMeetingRound round = ROUND_MAP.get(roundIndex);
Block preRoundFirstBlock = null;
BlockRoundData preRoundData = null;
if (null == round) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public PocMeetingRound getCurrentRound() {
return currentRound;
} | #vulnerable code
public PocMeetingRound getCurrentRound() {
Block currentBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData currentRoundData = new BlockRoundData(currentBlock.getHeader().getExtend());
PocMeetingRound round = ROUND_MAP.get(currentRou... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public BlockInfo request(long start, long end, long split) {
lock.lock();
this.startTime = TimeService.currentTimeMillis();
requesting = true;
hashesMap.clear();
calcMap.clear();
this.start = start;
this.end = end;
... | #vulnerable code
public BlockInfo request(long start, long end, long split) {
lock.lock();
this.startTime = TimeService.currentTimeMillis();
requesting = true;
hashesMap.clear();
calcMap.clear();
this.start = start;
this.end = end;... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Transaction getTx(NulsDigestData hash) {
TransactionPo po = txDao.get(hash.getDigestHex());
if (null != po) {
try {
Transaction tx = UtxoTransferTool.toTransaction(po);
return tx;
} c... | #vulnerable code
@Override
public Transaction getTx(NulsDigestData hash) {
TransactionLocalPo localPo = localTxDao.get(hash.getDigestHex());
if (localPo != null) {
try {
Transaction tx = UtxoTransferTool.toTransaction(localPo);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
VersionEvent event = (VersionEvent) networkEvent;
// String key = event.getHeader().getEventType() + "-" + node.getId();
// if (cacheService.existEvent(key)) {
// ... | #vulnerable code
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
VersionEvent event = (VersionEvent) networkEvent;
String key = event.getHeader().getEventType() + "-" + node.getId();
if (cacheService.existEvent(key)) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public boolean saveLocalTx(Transaction tx) throws IOException {
try {
ValidateResult validateResult = this.conflictDetectTx(tx, this.getWaitingTxList());
if (validateResult.isFailed()) {
throw new NulsRuntimeExcept... | #vulnerable code
@Override
public boolean saveLocalTx(Transaction tx) throws IOException {
try {
ValidateResult validateResult = this.conflictDetectTx(tx, this.getWaitingTxList());
if (validateResult.isFailed()) {
throw new NulsRuntime... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Result transfer(byte[] from, byte[] to, Na values, String password, String remark) {
try {
AssertUtil.canNotEmpty(from, "the from address can not be empty");
AssertUtil.canNotEmpty(to, "the to address can not be empty");
... | #vulnerable code
@Override
public Result transfer(byte[] from, byte[] to, Na values, String password, String remark) {
try {
AssertUtil.canNotEmpty(from, "the from address can not be empty");
AssertUtil.canNotEmpty(to, "the to address can not be empty... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void reset() {
lock.lock();try{
this.needReSet = true;
ROUND_MAP.clear();
this.init();}finally {
lock.unlock();
}
} | #vulnerable code
public void reset() {
this.needReSet = true;
}
#location 2
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private List<Transaction> getTxList(Block block, List<NulsDigestData> txHashList) {
List<Transaction> txList = new ArrayList<>();
for (Transaction tx : block.getTxs()) {
if (txHashList.contains(tx.getHash())) {
txList.add(tx);
... | #vulnerable code
private List<Transaction> getTxList(Block block, List<NulsDigestData> txHashList) {
List<Transaction> txList = new ArrayList<>();
Map<String, Integer> allTxMap = new HashMap<>();
for (int i = 0; i < block.getHeader().getTxCount(); i++) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void onMessage(GetBlockRequest message, Node fromNode) {
BlockSendThread.offer(message, fromNode);
} | #vulnerable code
@Override
public void onMessage(GetBlockRequest message, Node fromNode) throws NulsException {
GetBlockDataParam param = message.getMsgBody();
if (param.getSize() > MAX_SIZE) {
return;
}
if (param.getSize() == 1) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = roundData.getRoundIndex(); i >= 1 ... | #vulnerable code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = roundData.getRoundIndex(); i... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void requestTxGroup(NulsDigestData blockHash, String nodeId) {
GetTxGroupRequest request = new GetTxGroupRequest();
GetTxGroupParam data = new GetTxGroupParam();
data.setBlockHash(blockHash);
List<NulsDigestData> txHashList = new ArrayLi... | #vulnerable code
public void requestTxGroup(NulsDigestData blockHash, String nodeId) {
GetTxGroupRequest request = new GetTxGroupRequest();
GetTxGroupParam data = new GetTxGroupParam();
data.setBlockHash(blockHash);
List<NulsDigestData> txHashList = new A... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
@DbSession
public void save(CoinData coinData, Transaction tx) throws NulsException {
UtxoData utxoData = (UtxoData) coinData;
List<UtxoInputPo> inputPoList = new ArrayList<>();
List<UtxoOutput> spends = new ArrayList<>();
Li... | #vulnerable code
@Override
@DbSession
public void save(CoinData coinData, Transaction tx) throws NulsException {
UtxoData utxoData = (UtxoData) coinData;
List<UtxoInputPo> inputPoList = new ArrayList<>();
List<UtxoOutput> spends = new ArrayList<>();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void onEvent(SmallBlockEvent event, String fromId) {
ValidateResult result = event.getEventBody().verify();
if (result.isFailed()) {
return;
}
temporaryCacheManager.cacheSmallBlock(event.getEventBody());
... | #vulnerable code
@Override
public void onEvent(SmallBlockEvent event, String fromId) {
ValidateResult result = event.getEventBody().verify();
if (result.isFailed()) {
return;
}
temporaryCacheManager.cacheSmallBlock(event.getEventBody());
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void onEvent(BlockEvent event, String fromId) {
Block block = event.getEventBody();
ValidateResult result = block.verify();
if (result.isFailed()) {
if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
... | #vulnerable code
@Override
public void onEvent(BlockEvent event, String fromId) {
Block block = event.getEventBody();
ValidateResult result = block.verify();
if (result.isFailed()) {
if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start() {
List<Peer> peers = discovery.getLocalPeers(10);
if (peers.isEmpty()) {
peers = getSeedPeers();
}
for (Peer peer : peers) {
peer.setType(Peer.OUT);
addPeerToGroup(NetworkConstant.NETWORK... | #vulnerable code
public void start() {
List<Peer> peers = discovery.getLocalPeers(10);
if (peers.isEmpty()) {
peers = getSeedPeers();
}
for (Peer peer : peers) {
peer.setType(Peer.OUT);
addPeerToGroup(NetworkConstant.N... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
protected Block createBlock() {
// new a block header
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHeight(0);
blockHeader.setPreHash(NulsDigestData.calcDigestData("00000000000".getBytes()));
blockHeader.setTime(1L);
... | #vulnerable code
protected Block createBlock() {
// new a block header
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHeight(0);
blockHeader.setPreHash(NulsDigestData.calcDigestData("00000000000".getBytes()));
blockHeader.setTime(1L);... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\nchain:... | #vulnerable code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\n... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
Attribute<Node> nodeAttribute = channel.attr(key);
Node node = nodeAttribute.get();
String nodeId =... | #vulnerable code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
Attribute<Node> nodeAttribute = channel.attr(key);
Node node = nodeAttribute.get();
String no... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Transaction getTx(NulsDigestData hash) {
TransactionPo po = txDao.get(hash.getDigestHex());
if (null != po) {
try {
Transaction tx = UtxoTransferTool.toTransaction(po);
return tx;
} c... | #vulnerable code
@Override
public Transaction getTx(NulsDigestData hash) {
TransactionLocalPo localPo = localTxDao.get(hash.getDigestHex());
if (localPo != null) {
try {
Transaction tx = UtxoTransferTool.toTransaction(localPo);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Result<Account> importAccount(String prikey, String password) {
if (!ECKey.isValidPrivteHex(prikey)) {
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
}
Account account;
try {
account = Ac... | #vulnerable code
@Override
public Result<Account> importAccount(String prikey, String password) {
if (!ECKey.isValidPrivteHex(prikey)) {
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
}
Account account;
try {
accoun... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void reSendLocalTx() throws NulsException {
List<Transaction> txList = ledgerCacheService.getUnconfirmTxList();
List<Transaction> helpList = new ArrayList<>();
for (Transaction tx : txList) {
if (TimeService.currentTimeMillis() - tx... | #vulnerable code
private void reSendLocalTx() throws NulsException {
List<Transaction> txList = getLedgerCacheService().getUnconfirmTxList();
List<Transaction> helpList = new ArrayList<>();
for (Transaction tx : txList) {
if (TimeService.currentTimeMi... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean isLocalHasSeed(List<Account> accountList) {
for (Account account : accountList) {
for (String seedAddress : csManager.getSeedNodeList()) {
if (seedAddress.equals(account.getAddress().getBase58())) {
return... | #vulnerable code
public boolean isLocalHasSeed(List<Account> accountList) {
for (Account account : accountList) {
for (PocMeetingMember seed : this.getDefaultSeedList()) {
if (seed.getAgentAddress().equals(account.getAddress().getBase58())) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start() {
try {
ChannelFuture future = boot.connect(node.getIp(), node.getSeverPort()).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
... | #vulnerable code
public void start() {
try {
ChannelFuture future = boot.connect(node.getIp(), node.getSeverPort()).sync();
if (future.isSuccess()) {
socketChannel = (SocketChannel) future.channel();
} else {
Sy... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public List<Transaction> getWaitingTxList() throws NulsException {
return ledgerCacheService.getUnconfirmTxList();
} | #vulnerable code
@Override
public List<Transaction> getWaitingTxList() throws NulsException {
List<TransactionLocalPo> poList = localTxDao.getUnConfirmTxs();
List<Transaction> txList = new ArrayList<>();
for (TransactionLocalPo po : poList) {
Tran... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void start() {
this.waitForDependencyRunning(MessageBusConstant.MODULE_ID_MESSAGE_BUS);
this.waitForDependencyInited(ConsensusConstant.MODULE_ID_CONSENSUS);
this.initHandlers();
((DownloadServiceImpl) NulsContext.getService... | #vulnerable code
@Override
public void start() {
this.waitForDependencyRunning(MessageBusConstant.MODULE_ID_MESSAGE_BUS);
this.initHandlers();
((DownloadServiceImpl) NulsContext.getServiceBean(DownloadService.class)).start();
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
address = Address.fromHashs(byteBuffer.readByLengthByte());
alias = new String(byteBuffer.readByLengthByte());
encryptedPriKey = byteBuffer.readByLengthByte();
... | #vulnerable code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
alias = new String(byteBuffer.readByLengthByte());
address = new Address(new String(byteBuffer.readByLengthByte()));
encryptedPriKey = byteBuffer.readByLengthByt... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void calc() {
if (null == nodeIdList || nodeIdList.isEmpty()) {
throw new NulsRuntimeException(ErrorCode.FAILED, "success list of nodes is empty!");
}
int size = nodeIdList.size();
int halfSize = (size + 1) / 2;
//t... | #vulnerable code
private void calc() {
if (null == nodeIdList || nodeIdList.isEmpty()) {
throw new NulsRuntimeException(ErrorCode.FAILED, "success list of nodes is empty!");
}
int size = nodeIdList.size();
int halfSize = (size + 1) / 2;
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public TransferTransaction createTransferTx(CoinTransferData transferData, String password, String remark) throws Exception {
TransferTransaction tx = new TransferTransaction(transferData, password);
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));... | #vulnerable code
public TransferTransaction createTransferTx(CoinTransferData transferData, String password, String remark) throws Exception {
TransferTransaction tx = new TransferTransaction(transferData, password);
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCOD... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static void handleKey(SelectionKey key) {
ConnectionHandler handler = (ConnectionHandler) key.attachment();
try {
if (!key.isValid()) {
// Key has been cancelled, make sure the socket gets closed
System.out.pr... | #vulnerable code
public static void handleKey(SelectionKey key) {
ConnectionHandler handler = (ConnectionHandler) key.attachment();
try {
if (!key.isValid()) {
// Key has been cancelled, make sure the socket gets closed
System.... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public HeaderDigest getLastHd() {
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
if (list.size() > 0) {
return list.get(list.size() - 1);
}
return null;
} | #vulnerable code
public HeaderDigest getLastHd() {
if (null == lastHd) {
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
if(list.size() > 0) {
this.lastHd = list.get(list.size() - 1);
}
}
return las... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public double readDouble() throws NulsException { byte[] bytes = this.readByLengthByte();
if(null==bytes){
return 0;
}
return Utils.bytes2Double(bytes);
} | #vulnerable code
public double readDouble() throws NulsException {
return Utils.bytes2Double(this.readByLengthByte());
}
#location 2
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean addBlockHashResponse(String nodeId, BlockHashResponse response) {
if (!hashesMap.containsKey(nodeId)) {
return false;
}
if (!requesting) {
return false;
}
if (hashesMap.get(nodeId) == null) {
... | #vulnerable code
public boolean addBlockHashResponse(String nodeId, BlockHashResponse response) {
if (!hashesMap.containsKey(nodeId)) {
return false;
}
if (!requesting) {
return false;
}
if(hashesMap.get(nodeId)==null){
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public ValidateResult validate(AliasTransaction tx) {
Alias alias = tx.getTxData();
if (!Address.validAddress(alias.getAddress())) {
return ValidateResult.getFailedResult(ErrorCode.ADDRESS_ERROR);
}
if (!StringUtils.va... | #vulnerable code
@Override
public ValidateResult validate(AliasTransaction tx) {
Alias alias = tx.getTxData();
if (!Address.validAddress(alias.getAddress())) {
return ValidateResult.getFailedResult("The address format error");
}
if (!Strin... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start() {
List<Peer> peers = discovery.getLocalPeers(10);
if (peers.isEmpty()) {
peers = getSeedPeers();
}
for (Peer peer : peers) {
peer.setType(Peer.OUT);
addPeerToGroup(NetworkConstant.NETWORK... | #vulnerable code
public void start() {
List<Peer> peers = discovery.getLocalPeers(10);
if (peers.isEmpty()) {
peers = getSeedPeers();
}
for (Peer peer : peers) {
peer.setType(Peer.OUT);
addPeerToGroup(NetworkConstant.N... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public ValidateResult validate(AliasTransaction tx) {
Alias alias = tx.getTxData();
if (StringUtils.isBlank(alias.getAddress()) || new Address(alias.getAddress()).getHash().length != 23) {
return ValidateResult.getFailedResult("The ad... | #vulnerable code
@Override
public ValidateResult validate(AliasTransaction tx) {
Alias alias = tx.getTxData();
if (StringUtils.isBlank(alias.getAddress()) || new Address(alias.getAddress()).getHash().length != 23) {
return ValidateResult.getFailedResult("... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Set<K> keySet(String cacheTitle) {
Cache cache = this.cacheManager.getCache(cacheTitle);
if (null == cache) {
return new HashSet<>();
}
Iterator it = cache.iterator();
Set<K> set = new HashSet<>();
... | #vulnerable code
@Override
public Set<K> keySet(String cacheTitle) {
Iterator it = cacheManager.getCache(cacheTitle).iterator();
Set<K> set = new HashSet<>();
while (it.hasNext()) {
Cache.Entry<K, T> entry = (Cache.Entry<K, T>) it.next();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static Result createArea(String areaName) {
// prevent too many areas
if(AREAS.size() > (MAX -1)) {
return new Result(false, "KV_AREA_CREATE_ERROR");
}
if(StringUtils.isBlank(areaName)) {
return Result.getFailed(E... | #vulnerable code
public static Result createArea(String areaName) {
// prevent too many areas
if(AREAS.size() > (MAX -1)) {
return new Result(false, "KV_AREA_CREATE_ERROR");
}
if(StringUtils.isBlank(areaName)) {
return Result.getFa... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void nextRound() throws NulsException, IOException {
packingRoundManager.calc(getBestBlock());
PocMeetingRound round = packingRoundManager.getCurrentRound();
while (TimeService.currentTimeMillis() < round.getStartTime()) {
try {
... | #vulnerable code
private void nextRound() throws NulsException, IOException {
packingRoundManager.calc(getBestBlock());
while (TimeService.currentTimeMillis() < (packingRoundManager.getCurrentRound().getStartTime())) {
try {
Thread.sleep(100L)... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = roundData.getRoundIndex(); i >= 1 ... | #vulnerable code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = ro... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public PocMeetingRound getCurrentRound() {
return currentRound;
} | #vulnerable code
public PocMeetingRound getCurrentRound() {
Block currentBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData currentRoundData = new BlockRoundData(currentBlock.getHeader().getExtend());
PocMeetingRound round = ROUND_MAP.get(currentRou... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void rollbackAppraval(Block block) {
if (null == block) {
Log.warn("the block is null!");
return;
}
this.rollbackTxList(block.getTxs(), 0, block.getTxs().size());
Block preBlock =this.getBlock(block.getHeader().g... | #vulnerable code
private void rollbackAppraval(Block block) {
if (null == block) {
Log.warn("the block is null!");
return;
}
this.rollbackTxList(block.getTxs(), 0, block.getTxs().size());
PackingRoundManager.getValidateInstance().c... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = roundData.getRoundIndex(); i >= 1 ... | #vulnerable code
public void init() {
//load five(CACHE_COUNT) round from db on the start time ;
Block bestBlock = getBestBlock();
BlockRoundData roundData = new BlockRoundData(bestBlock.getHeader().getExtend());
for (long i = roundData.getRoundIndex(); i... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private PocMeetingRound calcNextRound(BlockHeader bestBlockHeader, long bestHeight, BlockRoundData bestRoundData) {
PocMeetingRound round = new PocMeetingRound();
round.setIndex(bestRoundData.getRoundIndex() + 1);
round.setStartTime(bestRoundData.getRo... | #vulnerable code
private PocMeetingRound calcNextRound(BlockHeader bestBlockHeader, long bestHeight, BlockRoundData bestRoundData) {
PocMeetingRound round = new PocMeetingRound();
round.setIndex(bestRoundData.getRoundIndex() + 1);
round.setStartTime(bestRoundData... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Result<Balance> getBalance(byte[] address) throws NulsException {
if (address == null || address.length != AddressTool.HASH_LENGTH) {
return Result.getFailed(AccountLedgerErrorCode.PARAMETER_ERROR);
}
if (!isLocalAccou... | #vulnerable code
@Override
public Result<Balance> getBalance(byte[] address) throws NulsException {
if (address == null || address.length != AddressTool.HASH_LENGTH) {
return Result.getFailed(AccountLedgerErrorCode.PARAMETER_ERROR);
}
if (!isLoca... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean processingBifurcation(long height) {
lock.lock();
try {
return this.bifurcateProcessor.processing(height);
} finally {
lock.unlock();
}
} | #vulnerable code
public boolean processingBifurcation(long height) {
return this.bifurcateProcessor.processing(height);
}
#location 2
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static UtxoOutputPo toOutputPojo(UtxoOutput output) {
UtxoOutputPo po = new UtxoOutputPo();
po.setTxHash(output.getTxHash().getDigestHex());
po.setOutIndex(output.getIndex());
po.setValue(output.getValue());
po.setLockTime(output... | #vulnerable code
public static UtxoOutputPo toOutputPojo(UtxoOutput output) {
UtxoOutputPo po = new UtxoOutputPo();
po.setTxHash(output.getTxHash().getDigestHex());
po.setOutIndex(output.getIndex());
po.setValue(output.getValue());
po.setLockTime(... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public ValidateResult validate(AbstractCoinTransaction tx) {
UtxoData data = (UtxoData) tx.getCoinData();
for (int i = 0; i < data.getInputs().size(); i++) {
UtxoInput input = data.getInputs().get(i);
UtxoOutput output = i... | #vulnerable code
@Override
public ValidateResult validate(AbstractCoinTransaction tx) {
UtxoData data = (UtxoData) tx.getCoinData();
for (int i = 0; i < data.getInputs().size(); i++) {
UtxoInput input = data.getInputs().get(i);
UtxoOutput outp... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void cacheBlockToBuffer(Block block) {
blockCacheBuffer.cacheBlock(block);
BlockLog.info("orphan cache block height:" + block.getHeader().getHeight() + ", preHash:" + block.getHeader().getPreHash() + " , hash:" + block.getHeader().getHash() + ", addres... | #vulnerable code
private void cacheBlockToBuffer(Block block) {
blockCacheBuffer.cacheBlock(block);
BlockLog.info("orphan cache block height:" + block.getHeader().getHeight() + ", preHash:" + block.getHeader().getPreHash() + " , hash:" + block.getHeader().getHash() + ", ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void newTx() throws Exception {
assertNotNull(service);
// new a tx
Transaction tx = new TestTransaction();
CoinData coinData = new CoinData();
List<Coin> fromList = new ArrayList<>();
fromList.add(new Coin(ne... | #vulnerable code
@Test
public void newTx() throws Exception {
assertNotNull(service);
// new a tx
Transaction tx = new TestTransaction();
CoinData coinData = new CoinData();
List<Coin> fromList = new ArrayList<>();
fromList.add(new C... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void init(Map<String, String> initParams) {
String databaseType = null;
if(initParams.get("databaseType") != null) {
databaseType = initParams.get("databaseType");
}
if (!StringUtils.isEmpty(databaseType) && has... | #vulnerable code
@Override
public void init(Map<String, String> initParams) {
String dataBaseType = null;
if(initParams.get("dataBaseType") != null) {
dataBaseType = initParams.get("dataBaseType");
}
if (!StringUtils.isEmpty(dataBaseType) ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start() {
List<Node> nodeList = getNetworkStorage().getLocalNodeList(20);
nodeList.addAll(getSeedNodes());
for (Node node : nodeList) {
addNode(node);
}
running = true;
TaskManager.createAndRunThread(Netw... | #vulnerable code
public void start() {
getNetworkStorage().init();
List<Node> nodeList = getNetworkStorage().getLocalNodeList(20);
nodeList.addAll(getSeedNodes());
for (Node node : nodeList) {
addNode(node);
}
running = true;
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public boolean resetSystem(String reason) {
if ((TimeService.currentTimeMillis() - lastResetTime) <= INTERVAL_TIME) {
Log.info("system reset interrupt!");
return true;
}
Log.info("---------------reset start--------... | #vulnerable code
@Override
public boolean resetSystem(String reason) {
if ((TimeService.currentTimeMillis() - lastResetTime) <= INTERVAL_TIME) {
Log.info("system reset interrupt!");
return true;
}
Log.info("---------------reset start--... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public HeaderDigest getLastHd() {
if (null == lastHd) {
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
this.lastHd = list.get(list.size() - 1);
}
return lastHd;
} | #vulnerable code
public HeaderDigest getLastHd() {
if(null==lastHd){
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
this.lastHd = list.get(list.size()-1);
}
return lastHd;
}
#location 6
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public NetworkEventResult process(BaseEvent event, Node node) {
GetNodeEvent getNodeEvent = (GetNodeEvent) event;
// String key = event.getHeader().getEventType() + "-" + node.getIp();
// if (cacheService.existEvent(key)) {
// g... | #vulnerable code
@Override
public NetworkEventResult process(BaseEvent event, Node node) {
GetNodeEvent getNodeEvent = (GetNodeEvent) event;
String key = event.getHeader().getEventType() + "-" + node.getIp();
if (cacheService.existEvent(key)) {
g... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public HeaderDigest getLastHd() {
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
if (list.size() > 0) {
return list.get(list.size() - 1);
}
return null;
} | #vulnerable code
public HeaderDigest getLastHd() {
if (null == lastHd) {
List<HeaderDigest> list = new ArrayList<>(headerDigestList);
if(list.size() > 0) {
this.lastHd = list.get(list.size() - 1);
}
}
return las... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean processing(long height) {
if (chainList.isEmpty()) {
return false;
}
this.checkIt();
if (null == approvingChain) {
return false;
}
Set<HeaderDigest> removeHashSet = new HashSet<>();
... | #vulnerable code
public boolean processing(long height) {
if (chainList.isEmpty()) {
return false;
}
this.checkIt();
if (null == approvingChain) {
return false;
}
if (approvingChain.getLastHd() != null && approvingC... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@PluginFactory
public static <S extends Serializable> SyslogAppender<S> createAppender(@PluginAttr("host") final String host,
@PluginAttr("port") final String portNum,
@PluginA... | #vulnerable code
@PluginFactory
public static <S extends Serializable> SyslogAppender<S> createAppender(@PluginAttr("host") final String host,
@PluginAttr("port") final String portNum,
@P... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private static OutputStream getOutputStream(final boolean follow, final Target target) {
final PrintStream printStream = target == Target.SYSTEM_OUT ?
follow ? new PrintStream(new SystemOutStream()) : System.out :
follow ? new PrintStream(new S... | #vulnerable code
private static OutputStream getOutputStream(final boolean follow, final Target target) {
final PrintStream printStream = target == Target.SYSTEM_OUT ?
follow ? new PrintStream(new SystemOutStream()) : System.out :
follow ? new PrintStream... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAppender() throws Exception {
for (int i = 0; i < 8; ++i) {
logger.debug("This is test message number " + i);
}
Thread.sleep(50);
final File dir = new File(DIR);
assertThat(dir, both(exists()).and(h... | #vulnerable code
@Test
public void testAppender() throws Exception {
for (int i = 0; i < 8; ++i) {
logger.debug("This is test message number " + i);
}
Thread.sleep(50);
final File dir = new File(DIR);
assertTrue("Directory not crea... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
if (socket == null) {
if (reconnector != null && !immediateFail) {
reconnector.latch();
}
if... | #vulnerable code
@Override
protected void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
if (socket == null) {
if (connector != null && !immediateFail) {
connector.latch();
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock(OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
final Logger... | #vulnerable code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock(OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
final ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private static void copyFile(final File source, final File destination) throws IOException {
if (!destination.exists()) {
destination.createNewFile();
}
FileChannel srcChannel = null;
FileChannel destChannel = null;
FileInp... | #vulnerable code
private static void copyFile(final File source, final File destination) throws IOException {
if (!destination.exists()) {
destination.createNewFile();
}
FileChannel srcChannel = null;
FileChannel destChannel = null;
t... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
Message msg = message instanceof Message ? (ObjectMessage) message : new ObjectMess... | #vulnerable code
public void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
logger.log(null, fqcn, lvl, new ObjectMessage(message), t);
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void addScript(Script script) {
ScriptEngine engine = manager.getEngineByName(script.getLanguage());
if (engine == null) {
logger.error("No ScriptEngine found for language " + script.getLanguage() + ". Available languages are: " +
... | #vulnerable code
public void addScript(Script script) {
ScriptEngine engine = manager.getEngineByName(script.getLanguage());
if (engine == null) {
logger.error("No ScriptEngine found for language " + script.getLanguage());
}
if (engine.getFact... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static void main(String[] args) throws Exception {
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
Logger logger = LogManager.getLogger();
if (!(logger instanceof AsyncLogger)) {
throw new Ill... | #vulnerable code
public static void main(String[] args) throws Exception {
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
Logger logger = LogManager.getLogger();
if (!(logger instanceof AsyncLogger)) {
throw n... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAppender() throws Exception {
final Logger logger = ctx.getLogger();
logger.debug("This is test message number 1");
Thread.sleep(1500);
// Trigger the rollover
for (int i = 0; i < 16; ++i) {
logger.... | #vulnerable code
@Test
public void testAppender() throws Exception {
final Logger logger = ctx.getLogger();
logger.debug("This is test message number 1");
Thread.sleep(1500);
// Trigger the rollover
for (int i = 0; i < 16; ++i) {
l... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public String toSerializable(final LogEvent event) {
final Message message = event.getMessage();
final Object[] parameters = message.getParameters();
final StringBuilder buffer = getStringBuilder();
// Revisit when 1.3 is out so t... | #vulnerable code
@Override
public String toSerializable(final LogEvent event) {
final Message message = event.getMessage();
final Object[] parameters = message.getParameters();
final StringBuilder buffer = prepareStringBuilder(strBuilder);
try {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean hasFilters() {
return filters.hasFilters();
} | #vulnerable code
public boolean hasFilters() {
return hasFilters;
}
#location 2
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
protected void releaseSub() {
if (rpcClient != null) {
try {
synchronized(this) {
try {
if (batchSize > 1 && batchEvent.getEvents().size() > 0) {
send(bat... | #vulnerable code
@Override
protected void releaseSub() {
if (rpcClient != null) {
try {
rpcClient.close();
} catch (final Exception ex) {
LOGGER.error("Attempt to close RPC client failed", ex);
}
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public EventRoute getEventRoute(final Level logLevel) {
final int remainingCapacity = remainingDisruptorCapacity();
if (remainingCapacity < 0) {
return EventRoute.DISCARD;
}
return asyncQueueFullPolicy.getRoute(backgro... | #vulnerable code
@Override
public EventRoute getEventRoute(final Level logLevel) {
final int remainingCapacity = remainingDisruptorCapacity();
if (remainingCapacity < 0) {
return EventRoute.DISCARD;
}
return asyncEventRouter.getRoute(backg... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static void main(final String[] args) throws Exception {
final JmsTopicReceiver receiver = new JmsTopicReceiver();
receiver.doMain(args);
} | #vulnerable code
public static void main(final String[] args) throws Exception {
if (args.length != 4) {
usage("Wrong number of arguments.");
}
final String tcfBindingName = args[0];
final String topicBindingName = args[1];
final Stri... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testConfig() {
final Configuration config = context.getConfiguration();
final Filter filter = config.getFilter();
assertNotNull("No StructuredDataFilter", filter);
assertTrue("Not a StructuredDataFilter", filter instanceof... | #vulnerable code
@Test
public void testConfig() {
final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-sdfilter.xml");
final Configuration config = ctx.getConfiguration();
final Filter filter = config.getFilter();
ass... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@BeforeClass
public static void setUpClass() throws Exception {
// TODO: refactor PluginManager.decode() into this module?
pluginCategories = new ConcurrentHashMap<String, ConcurrentMap<String, PluginEntry>>();
final Enumeration<URL> resources = Pl... | #vulnerable code
@BeforeClass
public static void setUpClass() throws Exception {
// TODO: refactor PluginManager.decode() into this module?
pluginCategories = new ConcurrentHashMap<String, ConcurrentMap<String, PluginEntry>>();
final Enumeration<URL> resource... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static void main(String[] args) throws Exception {
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
Logger logger = LogManager.getLogger();
if (!(logger instanceof AsyncLogger)) {
throw new Ill... | #vulnerable code
public static void main(String[] args) throws Exception {
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
Logger logger = LogManager.getLogger();
if (!(logger instanceof AsyncLogger)) {
throw n... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static boolean compare(final Class<?> testClass,
final String file1,
final String file2)
throws IOException {
try (final BufferedReader in1 = new BufferedReader(new FileReader(file1));
... | #vulnerable code
public static boolean compare(final Class<?> testClass,
final String file1,
final String file2)
throws IOException {
final BufferedReader in1 = new BufferedReader(new FileReader(file1));... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testMissingRootLogger() throws Exception {
final LoggerContext ctx = context.getContext();
final Logger logger = ctx.getLogger("sample.Logger1");
assertTrue("Logger should have the INFO level enabled", logger.isInfoEnabled());
... | #vulnerable code
@Test
public void testMissingRootLogger() throws Exception {
PluginManager.addPackage("org.apache.logging.log4j.test.appender");
final LoggerContext ctx = Configurator.initialize("Test1", "missingRootLogger.xml");
final Logger logger = LogMan... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static boolean execute(final File source, final File destination, final boolean deleteSource, final int level)
throws IOException {
if (source.exists()) {
try (final FileInputStream fis = new FileInputStream(source);
... | #vulnerable code
public static boolean execute(final File source, final File destination, final boolean deleteSource, final int level)
throws IOException {
if (source.exists()) {
final FileInputStream fis = new FileInputStream(source);
final FileO... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock("out", OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
try (... | #vulnerable code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock("out", OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testNoMsg() throws Exception {
final RegexFilter filter = RegexFilter.createFilter(".* test .*", null, false, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, ... | #vulnerable code
@Test
public void testNoMsg() {
final RegexFilter filter = RegexFilter.createFilter(Pattern.compile(".* test .*"), false, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testThresholds() {
final ThresholdFilter filter = ThresholdFilter.createFilter(Level.ERROR, null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null,... | #vulnerable code
@Test
public void testThresholds() {
final ThresholdFilter filter = ThresholdFilter.createFilter("ERROR", null, null);
filter.start();
assertTrue(filter.isStarted());
assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, nul... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testMemMapLocation() throws Exception {
final File f = new File(LOGFILE);
if (f.exists()) {
assertTrue(f.delete());
}
assertTrue(!f.exists());
final int expectedFileLength = Integers.ceilingNex... | #vulnerable code
@Test
public void testMemMapLocation() throws Exception {
final File f = new File(LOGFILE);
if (f.exists()) {
assertTrue(f.delete());
}
assertTrue(!f.exists());
final int expectedFileLength = Integers.ceil... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAppender() throws Exception {
for (int i=0; i < 100; ++i) {
logger.debug("This is test message number " + i);
}
Thread.sleep(50);
final File dir = new File(DIR);
assertThat(dir, both(exists()).and(h... | #vulnerable code
@Test
public void testAppender() throws Exception {
for (int i=0; i < 100; ++i) {
logger.debug("This is test message number " + i);
}
Thread.sleep(50);
final File dir = new File(DIR);
assertTrue("Directory not crea... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testByName() throws Exception {
LoggerContext ctx = Configurator.intitalize("-config", null, null);
Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
Configuration config = ctx.getConfiguration();
a... | #vulnerable code
@Test
public void testByName() throws Exception {
Configurator.intitalize("-config", null, null);
Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock(OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
final Logger... | #vulnerable code
@Test
public void testFlush() throws IOException {
final OutputStream out = EasyMock.createMock(OutputStream.class);
out.flush(); // expect the flush to come through to the mocked OutputStream
out.close();
replay(out);
final ... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static boolean execute(final File source, final File destination, final boolean deleteSource, final int level)
throws IOException {
if (source.exists()) {
try (final FileInputStream fis = new FileInputStream(source);
... | #vulnerable code
public static boolean execute(final File source, final File destination, final boolean deleteSource, final int level)
throws IOException {
if (source.exists()) {
final FileInputStream fis = new FileInputStream(source);
final FileO... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void logToFile() throws Exception {
final FileOutputStream fos = new FileOutputStream(LOGFILE, false);
fos.flush();
fos.close();
final Logger logger = LogManager.getLogger("org.apache.logging.log4j.test2.Test");
logger.... | #vulnerable code
@Test
public void logToFile() throws Exception {
final FileOutputStream fos = new FileOutputStream(LOGFILE, false);
fos.flush();
fos.close();
final Logger logger = LogManager.getLogger("org.apache.logging.log4j.test2.Test");
l... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
AsyncLoggerDisruptor(String contextName) {
this.contextName = contextName;
} | #vulnerable code
EventRoute getEventRoute(final Level logLevel) {
final int remainingCapacity = remainingDisruptorCapacity();
if (remainingCapacity < 0) {
return EventRoute.DISCARD;
}
return asyncEventRouter.getRoute(backgroundThreadId, logLev... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
static void reportResult(final String file, final String name, final Histogram histogram)
throws IOException {
final String result = createSamplingReport(name, histogram);
println(result);
if (file != null) {
final FileWriter w... | #vulnerable code
static void reportResult(final String file, final String name, final Histogram histogram)
throws IOException {
final String result = createSamplingReport(name, histogram);
println(result);
if (file != null) {
final FileWr... | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private static OutputStream getOutputStream(final boolean follow, final Target target) {
final PrintStream printStream = target == Target.SYSTEM_OUT ?
follow ? new PrintStream(new SystemOutStream()) : System.out :
follow ? new PrintStream(new S... | #vulnerable code
private static OutputStream getOutputStream(final boolean follow, final Target target) {
final PrintStream printStream = target == Target.SYSTEM_OUT ?
follow ? new PrintStream(new SystemOutStream()) : System.out :
follow ? new PrintStream... | Below is the vulnerable code, please generate the patch based on the following information. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.