input stringlengths 205 73.3k | output stringlengths 64 73.2k | instruction stringclasses 1
value |
|---|---|---|
#vulnerable code
@Override
protected void init() {
super.init();
currentAddress = stringsStartAddress;
full = false;
currentSegmentIndex = INDEX_NOT_YET_USED;
directMemoryService.setMemory(inUseSegmentAddress, totalSegmentCount, (byte) 0x00);
}
#loc... | #fixed code
@Override
protected void init() {
super.init();
currentAddress = stringsStartAddress;
full = false;
currentSegmentIndex = INDEX_NOT_YET_USED;
//directMemoryService.setMemory(inUseSegmentAddress, totalSegmentCount, (byte) 0x00);
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
protected void init(Class<T> elementType, long objectCount,
NonPrimitiveFieldAllocationConfigType allocateNonPrimitiveFieldsAtOffHeapConfigType,
DirectMemoryService directMemoryService) {
super.init(elementType, allocateNonPrimitiveFieldsAtOffHeapConfigType, dire... | #fixed code
protected void init(Class<T> elementType, long objectCount,
NonPrimitiveFieldAllocationConfigType allocateNonPrimitiveFieldsAtOffHeapConfigType,
DirectMemoryService directMemoryService) {
super.init(elementType, allocateNonPrimitiveFieldsAtOffHeapConfigType, directMemo... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
protected void init(Class<T> elementType, long objectCount,
NonPrimitiveFieldAllocationConfigType allocateNonPrimitiveFieldsAtOffHeapConfigType,
DirectMemoryService directMemoryService) {
super.init(elementType, allocateNonPrimitiveFieldsAtOffHeapConfigType, dire... | #fixed code
protected void init(Class<T> elementType, long objectCount,
NonPrimitiveFieldAllocationConfigType allocateNonPrimitiveFieldsAtOffHeapConfigType,
DirectMemoryService directMemoryService) {
super.init(elementType, allocateNonPrimitiveFieldsAtOffHeapConfigType, directMemo... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
protected long allocateStringFromOffHeap(String str) {
long addressOfStr = JvmUtil.addressOf(str);
char[] valueArray = (char[]) directMemoryService.getObject(str, valueArrayOffsetInString);
int valueArraySize = charArrayIndexStartOffset + (charArrayIndexScale * value... | #fixed code
protected long allocateStringFromOffHeap(String str) {
long addressOfStr = directMemoryService.addressOf(str);
char[] valueArray = (char[]) directMemoryService.getObject(str, valueArrayOffsetInString);
int valueArraySize = charArrayIndexStartOffset + (charArrayIndexScale *... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Test
public void objectRetrievedSuccessfullyFromLazyReferencedObjectOffHeapPool() {
LazyReferencedObjectOffHeapPool<SampleOffHeapClass> objectPool =
offHeapService.createOffHeapPool(
new ObjectOffHeapPoolCreateParameterBuilder<SampleOffHeapClass>().
... | #fixed code
@Test
public void objectRetrievedSuccessfullyFromLazyReferencedObjectOffHeapPool() {
LazyReferencedObjectOffHeapPool<SampleOffHeapClass> objectPool =
offHeapService.createOffHeapPool(
new ObjectOffHeapPoolCreateParameterBuilder<SampleOffHeapClass>().
type(S... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public A getArray() {
checkAvailability();
return objectArray;
}
#location 4
#vulnerability type THREAD_SAFETY_VIOLATION | #fixed code
@Override
public A getArray() {
checkAvailability();
return getObjectArray();
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
protected void init() {
super.init();
objectsStartAddress = allocationStartAddress;
// Allocated objects must start aligned as address size from start address of allocated address
long addressMod = objectsStartAddress % JvmUtil.OBJECT_ADDRESS_SENSIVIT... | #fixed code
@Override
protected void init() {
super.init();
long sourceAddress = offHeapSampleObjectAddress + 4;
long copySize = objectSize - 4;
// Copy sample object to allocated memory region for each object
for (long l = 0; l < objectCount; l++) {
long targetAddress = ob... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Test
public void sizeRetrievedSuccessfully() {
final int ENTRY_COUNT = Integer.SIZE - 1;
OffHeapJudyHashMap<Integer, Person> map =
new OffHeapJudyHashMap<Integer, Person>(Person.class);
for (int i = 0; i < ENTRY_COUNT; i++) {
map.put(i << i, randomOffHea... | #fixed code
@Test
public void sizeRetrievedSuccessfully() {
final int ENTRY_COUNT = Integer.SIZE - 1;
OffHeapJudyHashMap<Integer, Person> map =
new OffHeapJudyHashMap<Integer, Person>(Person.class);
for (int i = 0; i < ENTRY_COUNT; i++) {
map.put(i << i, randomizeOffHeapPe... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@SuppressWarnings("unchecked")
@Override
protected void init() {
super.init();
this.currentIndex = 0;
int arrayHeaderSize = JvmUtil.getArrayHeaderSize();
int arrayIndexScale = JvmUtil.arrayIndexScale(elementType);
long arrayIndexStartAddress = allocationS... | #fixed code
@SuppressWarnings("unchecked")
@Override
protected void init() {
super.init();
this.currentIndex = 0;
int arrayHeaderSize = JvmUtil.getArrayHeaderSize();
int arrayIndexScale = JvmUtil.arrayIndexScale(elementType);
long arrayIndexStartAddress = allocationStartAd... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@SuppressWarnings("deprecation")
protected void init(int estimatedStringCount, int estimatedStringLength) {
try {
this.estimatedStringCount = estimatedStringCount;
this.estimatedStringLength = estimatedStringLength;
charArrayIndexScale = JvmUtil.arrayIndexS... | #fixed code
@SuppressWarnings("deprecation")
protected void init(int estimatedStringCount, int estimatedStringLength) {
try {
this.estimatedStringCount = estimatedStringCount;
this.estimatedStringLength = estimatedStringLength;
charArrayIndexScale = JvmUtil.arrayIndexScale(c... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
protected long allocateStringFromOffHeap(String str) {
long addressOfStr = JvmUtil.addressOf(str);
char[] valueArray = (char[]) directMemoryService.getObject(str, valueArrayOffsetInString);
int valueArraySize = charArrayIndexStartOffset + (charArrayIndexScale * value... | #fixed code
protected long allocateStringFromOffHeap(String str) {
long addressOfStr = directMemoryService.addressOf(str);
char[] valueArray = (char[]) directMemoryService.getObject(str, valueArrayOffsetInString);
int valueArraySize = charArrayIndexStartOffset + (charArrayIndexScale *... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void packetSentRegardless(SocketFactory sf, ByteArrayOutputStream baos) {
ApnsConnectionImpl connection = new ApnsConnectionImpl(sf, "localhost", 80);
connection.DELAY_IN_MS = 0;
connection.sendMessage(msg);
Assert.assertArrayEqua... | #fixed code
private void packetSentRegardless(SocketFactory sf, ByteArrayOutputStream baos) {
ApnsConnectionImpl connection = new ApnsConnectionImpl(sf, "localhost", 80);
connection.DELAY_IN_MS = 0;
connection.sendMessage(msg);
Assert.assertArrayEquals(msg... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private synchronized Socket socket() throws NetworkIOException {
if (reconnectPolicy.shouldReconnect()) {
Utilities.close(socket);
socket = null;
}
if (socket == null || socket.isClosed()) {
try {
... | #fixed code
private synchronized Socket socket() throws NetworkIOException {
if (reconnectPolicy.shouldReconnect()) {
Utilities.close(socket);
socket = null;
}
if (socket == null || socket.isClosed()) {
try {
if... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public ApnsServiceBuilder withCert(String fileName, String password) {
try {
return withCert(new FileInputStream(fileName), password);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
... | #fixed code
public ApnsServiceBuilder withCert(String fileName, String password) {
FileInputStream stream = null;
try {
stream = new FileInputStream(fileName);
return withCert(stream, password);
} catch (FileNotFoundException e) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private synchronized Socket socket() throws NetworkIOException {
if (reconnectPolicy.shouldReconnect()) {
Utilities.close(socket);
socket = null;
}
if (socket == null || socket.isClosed()) {
try {
... | #fixed code
private synchronized Socket socket() throws NetworkIOException {
if (reconnectPolicy.shouldReconnect()) {
Utilities.close(socket);
socket = null;
}
if (socket == null || socket.isClosed()) {
try {
if... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void packetSentRegardless(SocketFactory sf, ByteArrayOutputStream baos) {
ApnsConnection connection = new ApnsConnection(sf, "localhost", 80);
connection.DELAY_IN_MS = 0;
connection.sendMessage(msg);
Assert.assertArrayEquals(msg.m... | #fixed code
private void packetSentRegardless(SocketFactory sf, ByteArrayOutputStream baos) {
ApnsConnectionImpl connection = new ApnsConnectionImpl(sf, "localhost", 80);
connection.DELAY_IN_MS = 0;
connection.sendMessage(msg);
Assert.assertArrayEquals(msg... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.setHeader(byteBuffer.readNulsData(new EventHeader()));
// version = new NulsVersion(byteBuffer.readShort());
bestBlockHeight = byteBuffer.readVarInt();
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void checkGenesisBlock() throws IOException {
Block genesisBlock = NulsContext.getInstance().getGenesisBlock();
genesisBlock.verify();
Block localGenesisBlock = this.blockService.getGengsisBlock();
if (null == localGenesisBlock) {
... | #fixed code
public void checkGenesisBlock() throws IOException {
Block genesisBlock = NulsContext.getInstance().getGenesisBlock();
genesisBlock.verify();
Block localGenesisBlock = this.blockService.getGengsisBlock();
if (null == localGenesisBlock) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public synchronized PocMeetingRound resetCurrentMeetingRound() {
Block currentBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData currentRoundData = new BlockRoundData(currentBlock.getHeader().getExtend());
PocMeetingRound currentRou... | #fixed code
public synchronized PocMeetingRound resetCurrentMeetingRound() {
Block currentBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData currentRoundData = new BlockRoundData(currentBlock.getHeader().getExtend());
PocMeetingRound currentRound = R... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public Block getHighestBlock() {
BlockHeaderChain chain = bifurcateProcessor.getApprovingChain();
if (null == chain) {
return null;
}
HeaderDigest headerDigest = chain.getLastHd();
return this.getBlock(headerDigest.get... | #fixed code
public Block getHighestBlock() {
BlockHeaderChain chain = bifurcateProcessor.getApprovingChain();
if (null == chain) {
return null;
}
HeaderDigest headerDigest = chain.getLastHd();
if(null==headerDigest){
return ... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void init() {
NulsContext.getServiceBean(AccountLedgerService.class).init();
//load local account list into cache
}
#location 3
#vulnerability type NULL_DEREFERENCE | #fixed code
@Override
public void init() {
//load local account list into cache
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | #fixed code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void init() {
accountService = NulsContext.getInstance().getService(AccountService.class);
//default local account
List<Account> list = this.accountService.getLocalAccountList();
if (null != list && !list.isEmpty()) {
L... | #fixed code
public void init() {
accountService = AccountServiceImpl.getInstance();
//default local account
List<Account> list = this.accountService.getLocalAccountList();
if (null != list && !list.isEmpty()) {
Locla_acount_id = list.get(0).get... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void destroy() {
System.out.println("---------peer destory:" + this.getIp());
lock.lock();
try {
this.status = Peer.CLOSE;
if (this.writeTarget != null) {
this.writeTarget.closeConnection();
... | #fixed code
public void destroy() {
lock.lock();
try {
this.status = Peer.CLOSE;
if (this.writeTarget != null) {
this.writeTarget.closeConnection();
this.writeTarget = null;
}
} finally {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void rollbackHeaderDigest(String hash) {
for (int i = 0; i < headerDigestList.size(); i++) {
HeaderDigest headerDigest = headerDigestList.get(i);
if (headerDigest.getHash().equals(hash)) {
headerDigestList.remove(he... | #fixed code
public void rollbackHeaderDigest(String hash) {
for (int i = 0; i < headerDigestList.size(); i++) {
HeaderDigest headerDigest = headerDigestList.get(i);
if (headerDigest.getHash().equals(hash)) {
headerDigestList.remove(headerDi... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void parse(NulsByteBuffer buffer) throws NulsException {
magicNumber = (int) buffer.readVarInt();
severPort = (int) buffer.readVarInt();
port = severPort;
ip = new String(buffer.readByLengthByte());
this.group... | #fixed code
@Override
public void parse(NulsByteBuffer buffer) throws NulsException {
magicNumber = buffer.readUint32();
severPort = buffer.readUint16();
port = severPort;
ip = buffer.readString();
this.groupSet = ConcurrentHashMap.newKeySet();... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void reSendLocalTx() throws NulsException {
List<Transaction> txList = getLedgerService().getWaitingTxList();
List<Transaction> helpList = new ArrayList<>();
for (Transaction tx : txList) {
if (TimeService.currentTimeMillis() ... | #fixed code
private void reSendLocalTx() throws NulsException {
List<Transaction> txList = getLedgerCacheService().getUnconfirmTxList();
List<Transaction> helpList = new ArrayList<>();
for (Transaction tx : txList) {
if (TimeService.currentTimeMillis()... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void start() {
consensusManager.init();
NulsContext.getInstance().setBestBlock(NulsContext.getServiceBean(BlockService.class).getLocalBestBlock());
this.registerHandlers();
this.consensusManager.startMaintenanceWork()... | #fixed code
@Override
public void start() {
consensusManager.init();
this.registerHandlers();
this.consensusManager.startMaintenanceWork();
consensusManager.joinConsensusMeeting();
consensusManager.startPersistenceWork();
Log.info("the... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private Block doPacking(PocMeetingMember self, PocMeetingRound round) throws NulsException, IOException {
Block bestBlock = this.blockService.getBestBlock();
List<Transaction> allTxList = txCacheManager.getTxList();
allTxList.sort(TxTimeComparat... | #fixed code
private Block doPacking(PocMeetingMember self, PocMeetingRound round) throws NulsException, IOException {
Block bestBlock = this.blockService.getBestBlock();
List<Transaction> allTxList = txCacheManager.getTxList();
allTxList.sort(TxTimeComparator.get... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public boolean createQueue(String queueName, long maxSize, int latelySecond) {
try {
InchainFQueue queue = new InchainFQueue(queueName, maxSize);
QueueManager.initQueue(queueName, queue, latelySecond);
return true;
} c... | #fixed code
public boolean createQueue(String queueName, long maxSize, int latelySecond) {
try {
NulsFQueue queue = new NulsFQueue(queueName, maxSize);
QueueManager.initQueue(queueName, queue, latelySecond);
return true;
} catch (Except... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public boolean downloadedBlock(String nodeId, Block block) {
try {
NodeDownloadingStatus status = nodeStatusMap.get(nodeId);
if (null == status) {
return false;
}
if (!status.containsHeight(block.ge... | #fixed code
public boolean downloadedBlock(String nodeId, Block block) {
if(!this.working){
return false;
}
try {
NodeDownloadingStatus status = nodeStatusMap.get(nodeId);
if (null == status) {
return false;
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public boolean canPersistence() {
return bifurcateProcessor.getLongestChain().size()> PocConsensusConstant.CONFIRM_BLOCK_COUNT;
}
#location 2
#vulnerability type NULL_DEREFERENCE | #fixed code
public boolean canPersistence() {
return null != bifurcateProcessor.getLongestChain() && bifurcateProcessor.getLongestChain().size() > PocConsensusConstant.CONFIRM_BLOCK_COUNT;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Test
public void getMemoryTxs() throws Exception {
assertNotNull(service);
Transaction tx = new TestTransaction();
tx.setTime(0l);
assertEquals(tx.getHash().getDigestHex(), "08001220d194faf5b314f54c3a299ca9ea086f3f8856c75dc44a1e0c... | #fixed code
@Test
public void getMemoryTxs() throws Exception {
assertNotNull(service);
Transaction tx = new TestTransaction();
tx.setTime(0l);
assertEquals(tx.getHash().getDigestHex(), "0020c7f397ae78f2c1d12b3edc916e8112bcac576a98444c4c26034c207c9a... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
Log.debug(" ---------------------- server ch... | #fixed code
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
Log.debug(" ---------------------- server channelI... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #fixed code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
address = Address.fromHashs(byteBuffer.readByLengthByte());
alias = new String(byteBuffer.readByLengthByte());
encryptedPriKey = byteBuffer.readByLengthByte();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
@DbSession
public void onRollback(StopAgentTransaction tx) {
Transaction joinTx = ledgerService.getTx(tx.getTxData());
if (joinTx.getType() == TransactionConstant.TX_TYPE_REGISTER_AGENT) {
RegisterAgentTransaction raTx = (Re... | #fixed code
@Override
@DbSession
public void onRollback(StopAgentTransaction tx) {
Transaction joinTx = ledgerService.getTx(tx.getTxData());
RegisterAgentTransaction raTx = (RegisterAgentTransaction) joinTx;
Consensus<Agent> ca = raTx.getTxData();
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public Result exportAccount(String address, String password) {
Account account = null;
if (!StringUtils.isBlank(address)) {
account = accountCacheService.getAccountByAddress(address);
if (account == null) {
... | #fixed code
@Override
public Result exportAccount(String address, String password) {
Account account = null;
if (!StringUtils.isBlank(address)) {
account = accountCacheService.getAccountByAddress(address);
if (account == null) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
Log.debug("---------------------- server c... | #fixed code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
Log.debug("---------------------- server channel... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void onEvent(BlockEvent event, String fromId) {
Block block = event.getEventBody();
if (null == block) {
Log.warn("recieved a null blockEvent form " + fromId);
return;
}
//BlockLog.debug("downl... | #fixed code
@Override
public void onEvent(BlockEvent event, String fromId) {
Block block = event.getEventBody();
if (null == block) {
Log.warn("recieved a null blockEvent form " + fromId);
return;
}
for (Transaction tx : block.... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public boolean containsKey(String cacheTitle, K key) {
boolean result = this.cacheManager.getCache(cacheTitle).containsKey(key);
return result;
}
#location 3
#vulnerability type ... | #fixed code
@Override
public boolean containsKey(String cacheTitle, K key) {
Cache cache = this.cacheManager.getCache(cacheTitle);
if (cache == null) {
return false;
}
boolean result = cache.containsKey(key);
return result;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void start() {
List<Node> nodes = discoverHandler.getLocalNodes(network.maxOutCount());
if (nodes == null && nodes.isEmpty()) {
nodes = getSeedNodes();
}
for (Node node : nodes) {
node.setType(Node.OUT);
... | #fixed code
public void start() {
List<Node> nodes = discoverHandler.getLocalNodes(network.maxOutCount());
if (nodes == null || nodes.isEmpty()) {
nodes = getSeedNodes();
}
for (Node node : nodes) {
node.setType(Node.OUT);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public synchronized void syncBlock() {
this.status = MaintenanceStatus.DOWNLOADING;
BestCorrectBlock bestCorrectBlock = checkLocalBestCorrentBlock();
boolean doit = false;
long startHeight = 1;
do {
if (null == bestCor... | #fixed code
public synchronized void syncBlock() {
this.status = MaintenanceStatus.DOWNLOADING;
while (true) {
BestCorrectBlock bestCorrectBlock = checkLocalBestCorrentBlock();
boolean doit = false;
long startHeight = 1;
d... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\n... | #fixed code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\nchain:... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void recalc(Block bestBlock) {
this.currentRound = null;
this.previousRound = null;
this.calc(bestBlock);
}
#location 4
#vulnerability type NULL_DEREFERENCE | #fixed code
private void recalc(Block bestBlock) {
this.currentRound = null;
this.calc(bestBlock);
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public LockNulsTransaction createLockNulsTx(CoinTransferData transferData, String password, String remark) throws Exception {
LockNulsTransaction tx = new LockNulsTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.s... | #fixed code
public LockNulsTransaction createLockNulsTx(CoinTransferData transferData, String password, String remark) throws Exception {
LockNulsTransaction tx = new LockNulsTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.setRema... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public PocMeetingRound getCurrentRound() {
if (needReSet) {
return null;
}
List<Account> accountList = accountService.getAccountList();
currentRound.calcLocalPacker(accountList);
return currentRound;
}
... | #fixed code
public PocMeetingRound getCurrentRound() {
List<Account> accountList = accountService.getAccountList();
currentRound.calcLocalPacker(accountList);
return currentRound;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public ValidateResult verifyCoinData(AbstractCoinTransaction tx, List<Transaction> txList) {
if (txList == null || txList.isEmpty()) {
//It's all an orphan that can go here
return ValidateResult.getFailedResult(ErrorCode.OR... | #fixed code
@Override
public ValidateResult verifyCoinData(AbstractCoinTransaction tx, List<Transaction> txList) {
if (txList == null || txList.isEmpty()) {
//It's all an orphan that can go here
return ValidateResult.getFailedResult(ErrorCode.ORPHAN_T... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void approve(CoinData coinData, Transaction tx) throws NulsException {
//spent the transaction specified output in the cache when the newly received transaction is approved.
UtxoData utxoData = (UtxoData) coinData;
for (UtxoI... | #fixed code
@Override
public void approve(CoinData coinData, Transaction tx) throws NulsException {
//spent the transaction specified output in the cache when the newly received transaction is approved.
UtxoData utxoData = (UtxoData) coinData;
for (UtxoInput i... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void sendMessage(AbstractNetworkMessage networkMessage) throws IOException {
if (this.getStatus() == Peer.CLOSE) {
return;
}
if (writeTarget == null) {
throw new NotYetConnectedException();
}
if (thi... | #fixed code
public void sendMessage(AbstractNetworkMessage networkMessage) throws IOException {
if (this.getStatus() == Peer.CLOSE) {
return;
}
if (writeTarget == null) {
throw new NotYetConnectedException();
}
if (this.stat... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | #fixed code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
NodeEvent event = (NodeEvent) networkEvent;
// String key = event.getHeader().getEventType() + "-" + node.getIp();
// if (cacheService.existEvent(key)) {
// ... | #fixed code
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
NodeEvent event = (NodeEvent) networkEvent;
Map<String, Node> outNodes = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP).getNodes();
boolean exist... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void onEvent(BlockHeaderEvent event, String fromId) {
if (DistributedBlockInfoRequestUtils.getInstance().addBlockHeader(fromId, event.getEventBody())) {
return;
}
BlockHeader header = event.getEventBody();
... | #fixed code
@Override
public void onEvent(BlockHeaderEvent event, String fromId) {
if (DistributedBlockInfoRequestUtils.getInstance().addBlockHeader(fromId, event.getEventBody())) {
return;
}
BlockHeader header = event.getEventBody();
block... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
// Log.debug(" ----------------------... | #fixed code
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
// Log.debug(" ---------------------- serve... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public Result<Integer> saveUnconfirmedTransaction(Transaction tx) {
return saveTransaction(tx, TransactionInfo.UNCONFIRMED);
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION | #fixed code
@Override
public Result<Integer> saveUnconfirmedTransaction(Transaction tx) {
saveLock.lock();
try {
ValidateResult result1 = tx.verify();
if (result1.isFailed()) {
return result1;
}
result1 =... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void onEvent(TransactionEvent event, String fromId) {
Transaction tx = event.getEventBody();
if (null == tx) {
return;
}
ValidateResult result = tx.verify();
if (result.isFailed()) {
if... | #fixed code
@Override
public void onEvent(TransactionEvent event, String fromId) {
Transaction tx = event.getEventBody();
if (null == tx) {
return;
}
ValidateResult result = tx.verify();
if (result.isFailed()) {
if (resu... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public Account getAccount(String address) {
AssertUtil.canNotEmpty(address, "");
Account account = accountCacheService.getAccountByAddress(address);
if (account == null) {
AliasPo aliasPo = aliasDataService.getByAddress(... | #fixed code
@Override
public Account getAccount(String address) {
AssertUtil.canNotEmpty(address, "");
Account account = accountCacheService.getAccountByAddress(address);
return account;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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;... | #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;
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
boolean verifyPublicKey(){
//verify the public-KEY-hashes are the same
byte[] publicKey = scriptSig.getPublicKey();
NulsDigestData digestData = NulsDigestData.calcDigestData(publicKey,NulsDigestData.DIGEST_ALG_SHA160);
if(Arrays.equals(d... | #fixed code
boolean verifyPublicKey(){
//verify the public-KEY-hashes are the same
byte[] publicKey = scriptSig.getPublicKey();
byte[] reedmAccount = Utils.sha256hash160(Utils.sha256hash160(publicKey));
if(Arrays.equals(reedmAccount,script.getPublicKeyDig... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void init() {
try {
NetworkContext.setNetworkConfig(ConfigLoader.loadProperties(NetworkConstant.NETWORK_PROPERTIES));
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(ErrorCod... | #fixed code
@Override
public void init() {
try {
NetworkContext.setNetworkConfig(ConfigLoader.loadProperties(NetworkConstant.NETWORK_PROPERTIES));
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(ErrorCode.IO_E... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public boolean containsSpend(String key) {
for (int i = 0; i < unSpends.size(); i++) {
UtxoOutput output = unSpends.get(i);
if (key.equals(output.getTxHash().getDigestHex() + "-" + output.getIndex())) {
return true;
... | #fixed code
public boolean containsSpend(String key) {
for (int i = 0; i < unSpends.size(); i++) {
UtxoOutput output = unSpends.get(i);
if (key.equals(output.getKey())) {
return true;
}
}
return false;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
Log.debug("---------------------- server c... | #fixed code
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
String nodeId = IpUtil.getNodeId(channel.remoteAddress());
// Log.info("---------------------- server channe... | Below is the vulnerable code, please generate the patch based on the following information. |
#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)) {
//... | #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)) {
// ... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void approve(CoinData coinData, Transaction tx) throws NulsException {
//spent the transaction specified output in the cache when the newly received transaction is approved.
UtxoData utxoData = (UtxoData) coinData;
for (UtxoI... | #fixed code
@Override
public void approve(CoinData coinData, Transaction tx) throws NulsException {
//spent the transaction specified output in the cache when the newly received transaction is approved.
UtxoData utxoData = (UtxoData) coinData;
for (UtxoInput i... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | #fixed code
public ValidateResult validate(BlockHeader header, List<Transaction> txs) {
if (header.getHeight() == 0) {
return ValidateResult.getSuccessResult();
}
BlockRoundData
roundData = new BlockRoundData(header.getExtend());
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public int getChainId(String chainName) {
return chain_id_map.get(chainName);
}
#location 2
#vulnerability type NULL_DEREFERENCE | #fixed code
public int getChainId(String chainName) {
return CHAIN_ID_MAP.get(chainName);
} | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public static String getPwd(){
System.out.print("Please enter the password, if the account has no password directly return.\nEnter your password:");
ConsoleReader reader = null;
try {
reader = new ConsoleReader();
String p... | #fixed code
public static String getPwd() {
return getPwd(null);
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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()));
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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;
}
... | #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;
}
... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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) {... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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());
boolean updateCacheStatus = true;
... | #fixed code
public void init() {
lock.lock();
try {
realInit();
} finally {
lock.unlock();
}
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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<>();
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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:" ... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
protected void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.setHeader(byteBuffer.readNulsData(new EventHeader()));
// version = new NulsVersion(byteBuffer.readShort());
bestBlockHeight = byteBuffer.readVarInt();
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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) {
... | #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) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public PocMeetingRound getCurrentRound() {
Block currentBlock = NulsContext.getInstance().getBestBlock();
BlockRoundData currentRoundData = new BlockRoundData(currentBlock.getHeader().getExtend());
PocMeetingRound round = ROUND_MAP.get(currentRou... | #fixed code
public PocMeetingRound getCurrentRound() {
return currentRound;
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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;... | #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;
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public Transaction getTx(NulsDigestData hash) {
TransactionLocalPo localPo = localTxDao.get(hash.getDigestHex());
if (localPo != null) {
try {
Transaction tx = UtxoTransferTool.toTransaction(localPo);
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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)) {
... | #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)) {
// ... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public boolean saveLocalTx(Transaction tx) throws IOException {
try {
ValidateResult validateResult = this.conflictDetectTx(tx, this.getWaitingTxList());
if (validateResult.isFailed()) {
throw new NulsRuntime... | #fixed code
@Override
public boolean saveLocalTx(Transaction tx) throws IOException {
try {
ValidateResult validateResult = this.conflictDetectTx(tx, this.getWaitingTxList());
if (validateResult.isFailed()) {
throw new NulsRuntimeExcept... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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");
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public boolean processing(long height) {
if (chainList.isEmpty()) {
return false;
}
lock.lock();
try {
List<String> hashList = this.getHashList(height);
if (hashList.size() == 1) {
retur... | #fixed code
public boolean processing(long height) {
if (chainList.isEmpty()) {
return false;
}
List<String> hashList = this.getHashList(height);
if (hashList.size() == 1) {
return true;
}
if (hashList.isEmpty()) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void reset() {
this.needReSet = true;
}
#location 2
#vulnerability type THREAD_SAFETY_VIOLATION | #fixed code
public void reset() {
lock.lock();try{
this.needReSet = true;
ROUND_MAP.clear();
this.init();}finally {
lock.unlock();
}
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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++) {
... | #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);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#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) {
... | #fixed code
@Override
public void onMessage(GetBlockRequest message, Node fromNode) {
BlockSendThread.offer(message, fromNode);
} | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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 ... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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<>();
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
@Override
public void onEvent(SmallBlockEvent event, String fromId) {
ValidateResult result = event.getEventBody().verify();
if (result.isFailed()) {
return;
}
temporaryCacheManager.cacheSmallBlock(event.getEventBody());
... | #fixed 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. |
#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) {
... | #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) {
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public Result saveLocalTx(Transaction tx) {
if (tx == null) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
byte[] txHashBytes = new byte[0];
try {
txHashBytes = tx.getHash().serialize();
} cat... | #fixed code
public Result saveLocalTx(Transaction tx) {
if (tx == null) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
byte[] txHashBytes = new byte[0];
try {
txHashBytes = tx.getHash().serialize();
} catch (IO... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
public void start() {
getNetworkStorage().init();
List<Node> nodeList = getNetworkStorage().getLocalNodeList(20);
nodeList.addAll(getSeedNodes());
for (Node node : nodeList) {
addNode(node);
}
running = true;
... | #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... | Below is the vulnerable code, please generate the patch based on the following information. |
#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);... | #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);
... | Below is the vulnerable code, please generate the patch based on the following information. |
#vulnerable code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\n... | #fixed code
private void checkIt() {
int maxSize = 0;
BlockHeaderChain longestChain = null;
StringBuilder str = new StringBuilder("++++++++++++++++++++++++chain info:");
for (BlockHeaderChain chain : chainList) {
str.append("+++++++++++\nchain:... | Below is the vulnerable code, please generate the patch based on the following information. |
#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)) {
//... | #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)) {
// ... | Below is the vulnerable code, please generate the patch based on the following information. |
#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... | #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 =... | 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.