input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putAddCount() { return putAddCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long rehashes() { return rehashes; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 10 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long size() { return size; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long removeCount() { return removeCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putAddCount() { return putAddCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 7 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code int hashTableSize() { return table.size(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 7 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 8 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long evictedEntries() { return evictedEntries; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long capacity, long cleanUpTriggerFree) { this.capacity = capacity; this.freeCapacity = capacity; this.cleanUpTriggerFree = cleanUpTriggerFree; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = new Table(roundUpToPowerOf2(hts)); double lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75d; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long hitCount() { return hitCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putAddCount() { return putAddCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long hitCount() { return hitCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 9 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putReplaceCount() { return putReplaceCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 6 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long hitCount() { return hitCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long rehashes() { return rehashes; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 9 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code boolean putEntry(long newHashEntryAdr, long hash, long keyLen, long bytes, boolean ifAbsent, long oldValueAdr, long oldValueLen) { long removeHashEntryAdr = 0L; LongArrayList derefList = null; lock.lock(); try { long hashEntryAdr; long ptr = table.bucketOffset(hash); for (int idx = 0; idx < entriesPerBucket; idx++, ptr += Util.BUCKET_ENTRY_LEN) { if ((hashEntryAdr = table.getEntryAdr(ptr)) == 0L) break; if (table.getHash(ptr) != hash) continue; // fetch allocLen here - same CPU cache line needed by key compare long allocLen = HashEntries.getAllocLen(hashEntryAdr); if (notSameKey(newHashEntryAdr, keyLen, hashEntryAdr)) continue; // replace existing entry if (ifAbsent) return false; if (oldValueAdr != 0L) { // code for replace() operation if (HashEntries.getValueLen(hashEntryAdr) != oldValueLen || !HashEntries.compare(hashEntryAdr, Util.ENTRY_OFF_DATA + Util.roundUpTo8(keyLen), oldValueAdr, 0L, oldValueLen)) return false; } freeCapacity += allocLen; table.removeFromTableWithOff(hashEntryAdr, ptr, idx); removeHashEntryAdr = hashEntryAdr; break; } if (freeCapacity < bytes) { derefList = new LongArrayList(); do { long eldestEntryAdr = table.removeEldest(); if (eldestEntryAdr == 0L) { if (removeHashEntryAdr != 0L) size--; return false; } freeCapacity += HashEntries.getAllocLen(eldestEntryAdr); size--; evictedEntries++; derefList.add(eldestEntryAdr); } while (freeCapacity < bytes); } if (removeHashEntryAdr == 0L) { if (size >= threshold) rehash(); size++; } if (!add(newHashEntryAdr, hash)) return false; freeCapacity -= bytes; if (removeHashEntryAdr == 0L) putAddCount++; else putReplaceCount++; return true; } finally { lock.unlock(); if (removeHashEntryAdr != 0L) HashEntries.dereference(removeHashEntryAdr); if (derefList != null) for (int i = 0; i < derefList.size(); i++) HashEntries.dereference(derefList.getLong(i)); } } #location 92 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long rehashes() { return rehashes; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long size() { return size; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 8 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 9 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long size() { return size; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 6 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 7 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 8 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long lruCompactions() { return lruCompactions; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long cleanUpCount() { return cleanUpCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long capacity, long cleanUpTriggerFree) { this.capacity = capacity; this.freeCapacity = capacity; this.cleanUpTriggerFree = cleanUpTriggerFree; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = new Table(roundUpToPowerOf2(hts)); double lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75d; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long size() { return size; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 7 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long lruCompactions() { return lruCompactions; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code int hashTableSize() { return table.size(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long capacity, long cleanUpTriggerFree) { this.capacity = capacity; this.freeCapacity = capacity; this.cleanUpTriggerFree = cleanUpTriggerFree; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = new Table(roundUpToPowerOf2(hts)); double lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75d; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putReplaceCount() { return putReplaceCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code boolean putEntry(long newHashEntryAdr, long hash, long keyLen, long bytes, boolean ifAbsent, long oldValueAddr, long oldValueOffset, long oldValueLen) { long removeHashEntryAdr = 0L; LongArrayList derefList = null; lock.lock(); try { long oldHashEntryAdr = 0L; long hashEntryAdr; long prevEntryAdr = 0L; for (hashEntryAdr = table.getFirst(hash); hashEntryAdr != 0L; prevEntryAdr = hashEntryAdr, hashEntryAdr = HashEntries.getNext(hashEntryAdr)) { if (notSameKey(newHashEntryAdr, hash, keyLen, hashEntryAdr)) continue; // replace existing entry if (ifAbsent) return false; if (oldValueAddr != 0L) { // code for replace() operation long valueLen = HashEntries.getValueLen(hashEntryAdr); if (valueLen != oldValueLen || !HashEntries.compare(hashEntryAdr, Util.ENTRY_OFF_DATA + Util.roundUpTo8(keyLen), oldValueAddr, oldValueOffset, oldValueLen)) return false; } removeInternal(hashEntryAdr, prevEntryAdr); removeHashEntryAdr = hashEntryAdr; oldHashEntryAdr = hashEntryAdr; break; } while (freeCapacity < bytes) { long eldestHashAdr = removeEldest(); if (eldestHashAdr == 0L) { if (oldHashEntryAdr != 0L) size--; return false; } if (derefList == null) derefList = new LongArrayList(); derefList.add(eldestHashAdr); } if (hashEntryAdr == 0L) { if (size >= threshold) rehash(); size++; } freeCapacity -= bytes; add(newHashEntryAdr, hash); if (hashEntryAdr == 0L) putAddCount++; else putReplaceCount++; return true; } finally { lock.unlock(); if (removeHashEntryAdr != 0L) HashEntries.dereference(removeHashEntryAdr); if (derefList != null) for (int i = 0; i < derefList.size(); i++) HashEntries.dereference(derefList.getLong(i)); } } #location 79 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long removeCount() { return removeCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 10 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long removeCount() { return removeCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long freeCapacity() { return freeCapacity; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code int hashTableSize() { return table.size(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long rehashes() { return rehashes; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long evictedEntries() { return evictedEntries; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long missCount() { return missCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE), throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putAddCount() { return putAddCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long evictedEntries() { return evictedEntries; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = Table.create((int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long putReplaceCount() { return putReplaceCount; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void release() { table.release(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long capacity, long cleanUpTriggerFree) { this.capacity = capacity; this.freeCapacity = capacity; this.cleanUpTriggerFree = cleanUpTriggerFree; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; table = new Table(roundUpToPowerOf2(hts)); double lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75d; this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void resetStatistics() { rehashes = 0L; evictedEntries = 0L; hitCount = 0L; missCount = 0L; putAddCount = 0L; putReplaceCount = 0L; removeCount = 0L; lruCompactions = 0L; } #location 5 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long evictedEntries() { return evictedEntries; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, AtomicLong freeCapacity) { this.freeCapacity = freeCapacity; int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code long freeCapacity() { return freeCapacity; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code OffHeapMap(OHCacheBuilder builder, long freeCapacity) { this.freeCapacity = freeCapacity; this.throwOOME = builder.isThrowOOME(); this.lock = builder.isUnlocked() ? null : new ReentrantLock(); int hts = builder.getHashTableSize(); if (hts <= 0) hts = 8192; if (hts < 256) hts = 256; int bl = builder.getBucketLength(); if (bl <= 0) bl = 8; int buckets = (int) Util.roundUpToPowerOf2(hts, MAX_TABLE_SIZE); entriesPerBucket = (int) Util.roundUpToPowerOf2(bl, MAX_TABLE_SIZE); table = Table.create(buckets, entriesPerBucket, throwOOME); if (table == null) throw new RuntimeException("unable to allocate off-heap memory for segment"); float lf = builder.getLoadFactor(); if (lf <= .0d) lf = .75f; if (lf >= 1d) throw new IllegalArgumentException("load factor must not be greater that 1"); this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public List<JadbDevice> getDevices() throws IOException, JadbException { Transport devices = createTransport(); devices.send("host:devices"); devices.verifyResponse(); String body = devices.readString(); devices.close(); return parseDevices(body); } #location 7 #vulnerability type RESOURCE_LEAK
#fixed code public List<JadbDevice> getDevices() throws IOException, JadbException { try (Transport transport = createTransport()) { transport.send("host:devices"); transport.verifyResponse(); String body = transport.readString(); return parseDevices(body); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void launch() throws IOException, InterruptedException { Process p = runtime.exec(new String[]{findAdbExecutable(), "start-server"}); p.waitFor(); int exitValue = p.exitValue(); if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code public void launch() throws IOException, InterruptedException { Process p = subprocess.execute(new String[]{executable, "start-server"}); p.waitFor(); int exitValue = p.exitValue(); if (exitValue != 0) throw new IOException("adb exited with exit code: " + exitValue); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void launch(Package name) throws IOException, JadbException { InputStream s = device.executeShell("monkey", "-p", name.toString(), "-c", "android.intent.category.LAUNCHER", "1"); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void launch(Package name) throws IOException, JadbException { InputStream s = device.executeShell("monkey", "-p", name.toString(), "-c", "android.intent.category.LAUNCHER", "1"); s.close(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void start() throws InterruptedException { thread = new Thread(this, "Fake Adb Server"); thread.setDaemon(true); thread.start(); synchronized (lockObject) { if (!isStarted) { lockObject.wait(); } } } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void start() throws InterruptedException { thread = new Thread(this, "Fake Adb Server"); thread.setDaemon(true); thread.start(); serverReady(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public String getHostVersion() throws IOException, JadbException { Transport main = createTransport(); main.send("host:version"); main.verifyResponse(); String version = main.readString(); main.close(); return version; } #location 7 #vulnerability type RESOURCE_LEAK
#fixed code public String getHostVersion() throws IOException, JadbException { try (Transport transport = createTransport()) { transport.send("host:version"); transport.verifyResponse(); return transport.readString(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Deprecated public void executeShell(OutputStream output, String command, String... args) throws IOException, JadbException { Transport transport = getTransport(); StringBuilder shellLine = new StringBuilder(command); for (String arg : args) { shellLine.append(" "); shellLine.append(Bash.quote(arg)); } send(transport, "shell:" + shellLine.toString()); if (output != null) { transport.readResponseTo(new AdbFilterOutputStream(output)); } } #location 11 #vulnerability type RESOURCE_LEAK
#fixed code @Deprecated public void executeShell(OutputStream output, String command, String... args) throws IOException, JadbException { Transport transport = getTransport(); StringBuilder shellLine = new StringBuilder(command); for (String arg : args) { shellLine.append(" "); shellLine.append(Bash.quote(arg)); } send(transport, "shell:" + shellLine.toString()); if (output != null) { AdbFilterOutputStream out = new AdbFilterOutputStream(output); try { transport.readResponseTo(out); } finally { out.close(); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void pull(RemoteFile remote, File local) throws IOException, JadbException { FileOutputStream fileStream = new FileOutputStream(local); pull(remote, fileStream); fileStream.close(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code public void pull(RemoteFile remote, File local) throws IOException, JadbException { try (FileOutputStream fileStream = new FileOutputStream(local)) { pull(remote, fileStream); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public List<RemoteFile> list(String remotePath) throws IOException, JadbException { Transport transport = getTransport(); SyncTransport sync = transport.startSync(); sync.send("LIST", remotePath); List<RemoteFile> result = new ArrayList<>(); for (RemoteFileRecord dent = sync.readDirectoryEntry(); dent != RemoteFileRecord.DONE; dent = sync.readDirectoryEntry()) { result.add(dent); } return result; } #location 10 #vulnerability type RESOURCE_LEAK
#fixed code public List<RemoteFile> list(String remotePath) throws IOException, JadbException { try (Transport transport = getTransport()) { SyncTransport sync = transport.startSync(); sync.send("LIST", remotePath); List<RemoteFile> result = new ArrayList<>(); for (RemoteFileRecord dent = sync.readDirectoryEntry(); dent != RemoteFileRecord.DONE; dent = sync.readDirectoryEntry()) { result.add(dent); } return result; } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Map<String, String> getprop() throws IOException, JadbException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(device.executeShell("getprop"))); return parseProp(bufferedReader); } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code public Map<String, String> getprop() throws IOException, JadbException { BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new InputStreamReader(device.executeShell("getprop"))); return parseProp(bufferedReader); } finally { if (bufferedReader != null) { bufferedReader.close(); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public String readString(int length) throws IOException { DataInput reader = new DataInputStream(inputStream); byte[] responseBuffer = new byte[length]; reader.readFully(responseBuffer); return new String(responseBuffer, StandardCharsets.UTF_8); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code public String readString(int length) throws IOException { byte[] responseBuffer = new byte[length]; dataInput.readFully(responseBuffer); return new String(responseBuffer, StandardCharsets.UTF_8); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void push(File local, RemoteFile remote) throws IOException, JadbException { FileInputStream fileStream = new FileInputStream(local); push(fileStream, local.lastModified(), getMode(local), remote); fileStream.close(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code public void push(File local, RemoteFile remote) throws IOException, JadbException { try (FileInputStream fileStream = new FileInputStream(local)) { push(fileStream, local.lastModified(), getMode(local), remote); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private byte[] passthrough(byte[] input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStream sut = new AdbFilterOutputStream(output); sut.write(input); sut.flush(); return output.toByteArray(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code private byte[] passthrough(byte[] input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); OutputStream sut = new AdbFilterOutputStream(output); try { sut.write(input); sut.flush(); } finally { sut.close(); } return output.toByteArray(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void runServer() throws IOException { DataInput input = new DataInputStream(socket.getInputStream()); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); while (true) { byte[] buffer = new byte[4]; input.readFully(buffer); String encodedLength = new String(buffer, StandardCharsets.UTF_8); int length = Integer.parseInt(encodedLength, 16); buffer = new byte[length]; input.readFully(buffer); String command = new String(buffer, StandardCharsets.UTF_8); responder.onCommand(command); try { if ("host:version".equals(command)) { output.writeBytes("OKAY"); send(output, String.format("%04x", responder.getVersion())); } else if ("host:transport-any".equals(command)) { // TODO: Check so that exactly one device is selected. selected = responder.getDevices().get(0); output.writeBytes("OKAY"); } else if ("host:devices".equals(command)) { ByteArrayOutputStream tmp = new ByteArrayOutputStream(); DataOutputStream writer = new DataOutputStream(tmp); for (AdbDeviceResponder d : responder.getDevices()) { writer.writeBytes(d.getSerial() + "\t" + d.getType() + "\n"); } output.writeBytes("OKAY"); send(output, new String(tmp.toByteArray(), StandardCharsets.UTF_8)); } else if (command.startsWith("host:transport:")) { String serial = command.substring("host:transport:".length()); selected = findDevice(serial); output.writeBytes("OKAY"); } else if ("sync:".equals(command)) { output.writeBytes("OKAY"); try { sync(output, input); } catch (JadbException e) { // sync response with a different type of fail message SyncTransport sync = getSyncTransport(output, input); sync.send("FAIL", e.getMessage()); } } else if (command.startsWith("shell:")) { String shellCommand = command.substring("shell:".length()); output.writeBytes("OKAY"); shell(shellCommand, output, input); output.close(); return; } else if ("host:get-state".equals(command)) { // TODO: Check so that exactly one device is selected. AdbDeviceResponder device = responder.getDevices().get(0); output.writeBytes("OKAY"); send(output, device.getType()); } else if (command.startsWith("host-serial:")) { String[] strs = command.split(":",0); if (strs.length != 3) { throw new ProtocolException("Invalid command: " + command); } String serial = strs[1]; boolean found = false; output.writeBytes("OKAY"); for (AdbDeviceResponder d : responder.getDevices()) { if (d.getSerial().equals(serial)) { send(output, d.getType()); found = true; break; } } if (!found) { send(output, "unknown"); } } else { throw new ProtocolException("Unknown command: " + command); } } catch (ProtocolException e) { output.writeBytes("FAIL"); send(output, e.getMessage()); } output.flush(); } } #location 79 #vulnerability type RESOURCE_LEAK
#fixed code private void runServer() throws IOException { DataInput input = new DataInputStream(socket.getInputStream()); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); while (processCommand(input, output)) { // nothing to do here } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void start() throws InterruptedException { thread = new Thread(this, "Fake Adb Server"); thread.setDaemon(true); thread.start(); synchronized (lockObject) { if (!isStarted) { lockObject.wait(); } } } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void start() throws InterruptedException { thread = new Thread(this, "Fake Adb Server"); thread.setDaemon(true); thread.start(); serverReady(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void vanilla() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TestConfiguration.class); Service service = context.getBean(Service.class); service.service(); assertEquals(3, service.getCount()); context.close(); } #location 9 #vulnerability type RESOURCE_LEAK
#fixed code @Test public void vanilla() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TestConfiguration.class); Service service = context.getBean(Service.class); Foo foo = context.getBean(Foo.class); assertFalse(AopUtils.isAopProxy(foo)); service.service(); assertEquals(3, service.getCount()); context.close(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testEmpytObjectCRC() { String key = "empty-object-crc"; try { // put PutObjectResult putObjectResult = ossClient.putObject(bucketName, key, new ByteArrayInputStream(new String("").getBytes())); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); String localFile = TestUtils.genFixedLengthFile(0); putObjectResult = ossClient.putObject(bucketName, key, new FileInputStream(localFile)); Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC()); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); putObjectResult = ossClient.putObject(bucketName, key, new File(localFile)); Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC()); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); // get OSSObject ossObject = ossClient.getObject(bucketName, key); Assert.assertNull(ossObject.getClientCRC()); Assert.assertNotNull(ossObject.getServerCRC()); Assert.assertTrue(IOUtils.getCRCValue(ossObject.getObjectContent()) == 0L); InputStream content = ossObject.getObjectContent(); while (content.read() != -1) { } ossObject.setClientCRC(IOUtils.getCRCValue(content)); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); content.close(); ossClient.deleteObject(bucketName, key); TestUtils.removeFile(localFile); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } } #location 28 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testEmpytObjectCRC() { String key = "empty-object-crc"; try { // put PutObjectResult putObjectResult = ossClient.putObject(bucketName, key, new ByteArrayInputStream(new String("").getBytes())); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN); String localFile = TestUtils.genFixedLengthFile(0); putObjectResult = ossClient.putObject(bucketName, key, new FileInputStream(localFile)); Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC()); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN); putObjectResult = ossClient.putObject(bucketName, key, new File(localFile)); Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC()); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN); // get OSSObject ossObject = ossClient.getObject(bucketName, key); Assert.assertNull(ossObject.getClientCRC()); Assert.assertNotNull(ossObject.getServerCRC()); Assert.assertEquals(ossObject.getRequestId().length(), REQUEST_ID_LEN); Assert.assertTrue(IOUtils.getCRCValue(ossObject.getObjectContent()) == 0L); InputStream content = ossObject.getObjectContent(); while (content.read() != -1) { } ossObject.setClientCRC(IOUtils.getCRCValue(content)); Assert.assertTrue(putObjectResult.getClientCRC() == 0L); Assert.assertTrue(putObjectResult.getServerCRC() == 0L); content.close(); ossClient.deleteObject(bucketName, key); TestUtils.removeFile(localFile); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void load(File file) throws IOException { InputStream in = new FileInputStream(file); load(in); in.close(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code public void load(File file) throws IOException { InputStream in = null; try { in = new FileInputStream(file); load(in); } finally { if (in != null) { in.close(); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String token = request.getHeader(Constant.TOKEN); if(StrUtil.isNotBlank(token)){ byte[] key = serialization.serialize(token); byte[] value = redisTemplate.getConnectionFactory().getConnection().get(key); Authentication authentication = serialization.deserialize(value,Authentication.class); SecurityContextHolder.getContext().setAuthentication(authentication); } chain.doFilter(request, response); } #location 6 #vulnerability type NULL_DEREFERENCE
#fixed code @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String token = request.getHeader(Constant.TOKEN); if(StrUtil.isNotBlank(token) && !StrUtil.equals(token,"null")){ Object userId = redisTemplate.opsForValue().get(token); if(ObjectUtil.isNull(userId)){ writer(response,"无效token"); return; } UserDetails userDetails = customUserDetailsService.loadUserByUserId((Long) userId); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); } chain.doFilter(request, response); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SneakyThrows @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication){ String token; if(authentication.getPrincipal() instanceof CustomUserDetailsUser){ CustomUserDetailsUser userDetailsUser = (CustomUserDetailsUser) authentication.getPrincipal(); token = SecureUtil.md5(userDetailsUser.getUsername() + System.currentTimeMillis()); }else { token = SecureUtil.md5(String.valueOf(System.currentTimeMillis())); } redisTemplate.opsForValue().set(Constant.AUTHENTICATION_TOKEN,token,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS); byte[] authenticationKey = redisTokenStoreSerializationStrategy.serialize(token); byte[] authenticationValue = redisTokenStoreSerializationStrategy.serialize(authentication); RedisConnection conn = redisTemplate.getConnectionFactory().getConnection(); try{ conn.openPipeline(); conn.set(authenticationKey, authenticationValue); conn.closePipeline(); }finally { conn.close(); } response.setCharacterEncoding(CharsetUtil.UTF_8); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); PrintWriter printWriter = response.getWriter(); printWriter.append(objectMapper.writeValueAsString(R.ok().put(Constant.TOKEN,token))); } #location 14 #vulnerability type NULL_DEREFERENCE
#fixed code @SneakyThrows @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication){ String token; Long userId = 0l; if(authentication.getPrincipal() instanceof CustomUserDetailsUser){ CustomUserDetailsUser userDetailsUser = (CustomUserDetailsUser) authentication.getPrincipal(); token = SecureUtil.md5(userDetailsUser.getUsername() + System.currentTimeMillis()); userId = userDetailsUser.getUserId(); }else { token = SecureUtil.md5(String.valueOf(System.currentTimeMillis())); } redisTemplate.opsForValue().set(Constant.AUTHENTICATION_TOKEN + token,token,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS); redisTemplate.opsForValue().set(token,userId,Constant.TOKEN_EXPIRE, TimeUnit.SECONDS); response.setCharacterEncoding(CharsetUtil.UTF_8); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); PrintWriter printWriter = response.getWriter(); printWriter.append(objectMapper.writeValueAsString(R.ok().put(Constant.TOKEN,token))); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SneakyThrows @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { String token = request.getHeader(Constant.TOKEN); redisTemplate.delete(Constant.AUTHENTICATION_TOKEN); byte[] authenticationKey = redisTokenStoreSerializationStrategy.serialize(token); RedisConnection conn = redisTemplate.getConnectionFactory().getConnection(); try{ conn.openPipeline(); conn.get(authenticationKey); conn.del(authenticationKey); conn.closePipeline(); }finally { conn.close(); } } #location 7 #vulnerability type NULL_DEREFERENCE
#fixed code @SneakyThrows @Override public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { String token = request.getHeader(Constant.TOKEN); redisTemplate.delete(Constant.AUTHENTICATION_TOKEN); redisTemplate.delete(token); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private List<BOBRequestDetail> getRequestBOBDetails() { if (requestBOBDetails == null) { List<String> detailLines = getDetailLines(); if (detailLines == null) return null; BOBRequestDetail detail; requestBOBDetails = new ArrayList<>(); for (String detailLine : detailLines) { detail = parseDetailLinesToRequestBOBDetail(detailLine); setNonGMGValues(detail); //FSIS-2993 //2018.04.28 address type must be upper case if(StringUtils.isNotEmpty(detail.getAddressType())) { detail.setAddressType(detail.getAddressType().toUpperCase()); } requestBOBDetails.add(detail); } } return requestBOBDetails; } #location 15 #vulnerability type NULL_DEREFERENCE
#fixed code private List<BOBRequestDetail> getRequestBOBDetails() { if (requestBOBDetails == null) { List<String> detailLines = getDetailLines(); if (detailLines == null) return null; BOBRequestDetail detail; requestBOBDetails = new ArrayList<>(); for (String detailLine : detailLines) { detail = parseDetailLinesToRequestBOBDetail(detailLine); requestBOBDetails.add(detail); } } return requestBOBDetails; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String getResponseBody() throws IOException { String contentType = getContentType(); String charset = "UTF-8"; if (contentType != null) { for (String part : contentType.split(";")) { if (part.startsWith("charset=")) { charset = part.substring("charset=".length()); } } } InputStream responseInput = getResponseBodyAsStream(); return contentToString(charset); } #location 12 #vulnerability type RESOURCE_LEAK
#fixed code @Override public String getResponseBody() throws IOException { String contentType = getContentType(); String charset = "UTF-8"; if (contentType != null) { for (String part : contentType.split(";")) { if (part.startsWith("charset=")) { charset = part.substring("charset=".length()); } } } return contentToString(charset); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String getResponseBodyExcerpt(int maxLength) throws IOException { String contentType = getContentType(); String charset = "UTF-8"; if (contentType != null) { for (String part : contentType.split(";")) { if (part.startsWith("charset=")) { charset = part.substring("charset=".length()); } } } InputStream responseInput = getResponseBodyAsStream(); String response = contentToString(charset); return response.length() <= maxLength ? response : response.substring(0,maxLength); } #location 12 #vulnerability type RESOURCE_LEAK
#fixed code @Override public String getResponseBodyExcerpt(int maxLength) throws IOException { String contentType = getContentType(); String charset = "UTF-8"; if (contentType != null) { for (String part : contentType.split(";")) { if (part.startsWith("charset=")) { charset = part.substring("charset=".length()); } } } String response = contentToString(charset); return response.length() <= maxLength ? response : response.substring(0,maxLength); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code Results run(String tomlString) { if (tomlString.isEmpty()) { return results; } String[] lines = tomlString.split("[\\n\\r]"); StringBuilder multilineBuilder = new StringBuilder(); Multiline multiline = Multiline.NONE; String key = null; String value = null; for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line != null && multiline.isTrimmable()) { line = line.trim(); } if (isComment(line) || line.isEmpty()) { continue; } if (isTableArray(line)) { String tableName = getTableArrayName(line); if (tableName != null) { results.startTableArray(tableName); String afterTableName = line.substring(tableName.length() + 4); if (!isComment(afterTableName)) { results.errors.append("Invalid table array definition: " + line + "\n\n"); } } else { results.errors.append("Invalid table array definition: " + line + "\n\n"); } continue; } if (multiline.isNotMultiline() && isTable(line)) { String tableName = getTableName(line); if (tableName != null) { results.startTables(tableName); } else { results.errors.append("Invalid table definition: " + line + "\n\n"); } continue; } if (multiline.isNotMultiline() && !line.contains("=")) { results.errors.append("Invalid key definition: " + line); continue; } String[] pair = line.split("=", 2); if (multiline.isNotMultiline() && MULTILINE_ARRAY_REGEX.matcher(pair[1].trim()).matches()) { multiline = Multiline.ARRAY; key = pair[0].trim(); multilineBuilder.append(removeComment(pair[1])); continue; } if (multiline.isNotMultiline() && pair[1].trim().startsWith("\"\"\"")) { multiline = Multiline.STRING; multilineBuilder.append(pair[1]); key = pair[0].trim(); if (pair[1].trim().indexOf("\"\"\"", 3) > -1) { multiline = Multiline.NONE; pair[1] = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { if (multilineBuilder.toString().trim().length() > 3) { multilineBuilder.append('\n'); } continue; } } if (multiline.isNotMultiline() && pair[1].trim().startsWith(STRING_LITERAL_DELIMITER)) { multiline = Multiline.STRING_LITERAL; multilineBuilder.append(pair[1]); key = pair[0].trim(); if (pair[1].trim().indexOf(STRING_LITERAL_DELIMITER, 3) > -1) { multiline = Multiline.NONE; pair[1] = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { if (multilineBuilder.toString().trim().length() > 3) { multilineBuilder.append('\n'); } continue; } } if (multiline == Multiline.ARRAY) { String lineWithoutComment = removeComment(line); multilineBuilder.append(lineWithoutComment); if (MULTILINE_ARRAY_REGEX_END.matcher(lineWithoutComment).matches()) { multiline = Multiline.NONE; value = multilineBuilder.toString(); multilineBuilder.delete(0, multilineBuilder.length()); } else { continue; } } else if (multiline == Multiline.STRING) { multilineBuilder.append(line); if (line.contains("\"\"\"")) { multiline = Multiline.NONE; value = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { multilineBuilder.append('\n'); continue; } } else if (multiline == Multiline.STRING_LITERAL) { multilineBuilder.append(line); if (line.contains(STRING_LITERAL_DELIMITER)) { multiline = Multiline.NONE; value = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { multilineBuilder.append('\n'); continue; } } else { key = pair[0].trim(); value = pair[1].trim(); } if (!isKeyValid(key)) { results.errors.append("Invalid key name: " + key + "\n"); continue; } Object convertedValue = VALUE_ANALYSIS.convert(value); if (convertedValue != INVALID) { results.addValue(key, convertedValue); } else { results.errors.append("Invalid key/value: " + key + " = " + value + "\n"); } } if (multiline != Multiline.NONE) { results.errors.append("Unterminated multiline " + multiline.toString().toLowerCase().replace('_', ' ') + "\n"); } return results; } #location 133 #vulnerability type NULL_DEREFERENCE
#fixed code Results run(String tomlString) { if (tomlString.isEmpty()) { return results; } String[] lines = tomlString.split("[\\n\\r]"); StringBuilder multilineBuilder = new StringBuilder(); Multiline multiline = Multiline.NONE; String key = null; String value = null; for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line != null && multiline.isTrimmable()) { line = line.trim(); } if (isComment(line) || line.isEmpty()) { continue; } if (isTableArray(line)) { String tableName = Keys.getTableArrayName(line); if (tableName != null) { results.startTableArray(tableName); String afterTableName = line.substring(tableName.length() + 4); if (!isComment(afterTableName)) { results.errors.append("Invalid table array definition: " + line + "\n\n"); } } else { results.errors.append("Invalid table array definition: " + line + "\n\n"); } continue; } if (multiline.isNotMultiline() && isTable(line)) { String tableName = Keys.getTableName(line); if (tableName != null) { results.startTables(tableName); } else { results.errors.append("Invalid table definition: " + line + "\n\n"); } continue; } if (multiline.isNotMultiline() && !line.contains("=")) { results.errors.append("Invalid key definition: " + line); continue; } String[] pair = line.split("=", 2); if (multiline.isNotMultiline() && MULTILINE_ARRAY_REGEX.matcher(pair[1].trim()).matches()) { multiline = Multiline.ARRAY; key = pair[0].trim(); multilineBuilder.append(removeComment(pair[1])); continue; } if (multiline.isNotMultiline() && pair[1].trim().startsWith("\"\"\"")) { multiline = Multiline.STRING; multilineBuilder.append(pair[1]); key = pair[0].trim(); if (pair[1].trim().indexOf("\"\"\"", 3) > -1) { multiline = Multiline.NONE; pair[1] = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { if (multilineBuilder.toString().trim().length() > 3) { multilineBuilder.append('\n'); } continue; } } if (multiline.isNotMultiline() && pair[1].trim().startsWith(STRING_LITERAL_DELIMITER)) { multiline = Multiline.STRING_LITERAL; multilineBuilder.append(pair[1]); key = pair[0].trim(); if (pair[1].trim().indexOf(STRING_LITERAL_DELIMITER, 3) > -1) { multiline = Multiline.NONE; pair[1] = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { if (multilineBuilder.toString().trim().length() > 3) { multilineBuilder.append('\n'); } continue; } } if (multiline == Multiline.ARRAY) { String lineWithoutComment = removeComment(line); multilineBuilder.append(lineWithoutComment); if (MULTILINE_ARRAY_REGEX_END.matcher(lineWithoutComment).matches()) { multiline = Multiline.NONE; value = multilineBuilder.toString(); multilineBuilder.delete(0, multilineBuilder.length()); } else { continue; } } else if (multiline == Multiline.STRING) { multilineBuilder.append(line); if (line.contains("\"\"\"")) { multiline = Multiline.NONE; value = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { multilineBuilder.append('\n'); continue; } } else if (multiline == Multiline.STRING_LITERAL) { multilineBuilder.append(line); if (line.contains(STRING_LITERAL_DELIMITER)) { multiline = Multiline.NONE; value = multilineBuilder.toString().trim(); multilineBuilder.delete(0, multilineBuilder.length()); } else { multilineBuilder.append('\n'); continue; } } else { key = Keys.getKey(pair[0]); if (key == null) { results.errors.append("Invalid key name: " + pair[0] + "\n"); continue; } value = pair[1].trim(); } Object convertedValue = VALUE_ANALYSIS.convert(value); if (convertedValue != INVALID) { results.addValue(key, convertedValue); } else { results.errors.append("Invalid key/value: " + key + " = " + value + "\n"); } } if (multiline != Multiline.NONE) { results.errors.append("Unterminated multiline " + multiline.toString().toLowerCase().replace('_', ' ') + "\n"); } return results; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private String readFile(File input) throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader(input)); StringBuilder w = new StringBuilder(); String line = bufferedReader.readLine(); while (line != null) { w.append(line).append('\n'); line = bufferedReader.readLine(); } return w.toString(); } #location 11 #vulnerability type RESOURCE_LEAK
#fixed code private String readFile(File input) throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader(input)); try { StringBuilder w = new StringBuilder(); String line = bufferedReader.readLine(); while (line != null) { w.append(line).append('\n'); line = bufferedReader.readLine(); } return w.toString(); } finally { bufferedReader.close(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SuppressWarnings("unchecked") @Test public void should_parse_example() throws Exception { TomlParser parser = Parboiled.createParser(TomlParser.class); String toml = new Scanner(new File(getClass().getResource("example.toml").getFile())).useDelimiter("\\Z").next(); ParsingResult<Object> result = new RecoveringParseRunner<Object>(parser.Toml()).run(toml); Map<String, Object> root = (Map<String, Object>) result.valueStack.peek(result.valueStack.size() - 2); // printMap(root); assertEquals("TOML Example", root.get("title")); Map<String, Object> owner = get(root, "owner"); assertEquals("Tom Preston-Werner", owner.get("name")); assertEquals("GitHub", owner.get("organization")); assertEquals("GitHub Cofounder & CEO\nLikes tater tots and beer.", owner.get("bio")); Calendar dob = Calendar.getInstance(); dob.set(1979, Calendar.MAY, 27, 7, 32, 0); dob.set(Calendar.MILLISECOND, 0); dob.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals(dob.getTime(), owner.get("dob")); Map<String, Object> database = get(root, "database"); assertEquals("192.168.1.1", database.get("server")); assertEquals(5000L, database.get("connection_max")); assertTrue((Boolean) database.get("enabled")); assertEquals(Arrays.asList(8001L, 8001L, 8002L), database.get("ports")); Map<String, Object> servers = get(root, "servers"); Map<String, Object> alphaServers = get(servers, "alpha"); assertEquals("10.0.0.1", alphaServers.get("ip")); assertEquals("eqdc10", alphaServers.get("dc")); Map<String, Object> betaServers = get(servers, "beta"); assertEquals("10.0.0.2", betaServers.get("ip")); assertEquals("eqdc10", betaServers.get("dc")); Map<String, Object> clients = get(root, "clients"); assertEquals(asList(asList("gamma", "delta"), asList(1L, 2L)), clients.get("data")); assertEquals(asList("alpha", "omega"), clients.get("hosts")); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code @SuppressWarnings("unchecked") @Test public void should_parse_example() throws Exception { Toml toml = new Toml().parse(new File(getClass().getResource("example.toml").getFile())); // printMap(root); assertEquals("TOML Example", toml.getString("title")); Toml owner = toml.getKeyGroup("owner"); assertEquals("Tom Preston-Werner", owner.getString("name")); assertEquals("GitHub", owner.getString("organization")); assertEquals("GitHub Cofounder & CEO\nLikes tater tots and beer.", owner.getString("bio")); Calendar dob = Calendar.getInstance(); dob.set(1979, Calendar.MAY, 27, 7, 32, 0); dob.set(Calendar.MILLISECOND, 0); dob.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals(dob.getTime(), owner.getDate("dob")); Toml database = toml.getKeyGroup("database"); assertEquals("192.168.1.1", database.getString("server")); assertEquals(5000L, database.getLong("connection_max").longValue()); assertTrue(database.getBoolean("enabled")); assertEquals(Arrays.asList(8001L, 8001L, 8002L), database.getList("ports", Long.class)); Toml servers = toml.getKeyGroup("servers"); Toml alphaServers = servers.getKeyGroup("alpha"); assertEquals("10.0.0.1", alphaServers.getString("ip")); assertEquals("eqdc10", alphaServers.getString("dc")); Toml betaServers = servers.getKeyGroup("beta"); assertEquals("10.0.0.2", betaServers.getString("ip")); assertEquals("eqdc10", betaServers.getString("dc")); Toml clients = toml.getKeyGroup("clients"); assertEquals(asList(asList("gamma", "delta"), asList(1L, 2L)), clients.getList("data", String.class)); assertEquals(asList("alpha", "omega"), clients.getList("hosts", String.class)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void write(Object from, File target) throws IOException { FileWriter writer = new FileWriter(target); writer.write(write(from)); writer.close(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code public void write(Object from, File target) throws IOException { FileWriter writer = new FileWriter(target); write(from, writer); writer.close(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void write(Object from, OutputStream target) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(target); write(from, writer); writer.flush(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code public void write(Object from, OutputStream target) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(target, "UTF-8"); write(from, writer); writer.flush(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void write(Object from, OutputStream target) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(target); write(from, writer); writer.flush(); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code public void write(Object from, OutputStream target) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(target, "UTF-8"); write(from, writer); writer.flush(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Toml parse(File file) { try { return parse(new Scanner(file).useDelimiter("\\Z").next()); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code public Toml parse(File file) { Scanner scanner = null; try { scanner = new Scanner(file); return parse(scanner.useDelimiter("\\Z").next()); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { if (scanner != null) { scanner.close(); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean filmlisteIstAelter(int sekunden) { // Filmliste ist älter als: FilmeLaden.ALTER_FILMLISTE_SEKUNDEN_FUER_AUTOUPDATE int ret = -1; Date jetzt = new Date(System.currentTimeMillis()); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm"); String date = metaDaten[ListeFilme.FILMLISTE_DATUM_NR]; Date filmDate = null; try { filmDate = sdf.parse(date); } catch (ParseException ex) { } if (jetzt != null && filmDate != null) { ret = Math.round((jetzt.getTime() - filmDate.getTime()) / (1000)); ret = Math.abs(ret); } if (ret != -1) { Log.systemMeldung("Die Filmliste ist " + ret / 60 + " Minuten alt"); } if (ret > sekunden) { return true; } else if (ret == -1) { return true; } return false; } #location 6 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public boolean filmlisteIstAelter(int sekunden) { int ret = alterFilmlisteSek(); // Date jetzt = new Date(System.currentTimeMillis()); // SimpleDateFormat sdf = new SimpleDateFormat(DATUM_ZEIT_FORMAT); // String date = metaDaten[ListeFilme.FILMLISTE_DATUM_NR]; // Date filmDate = null; // try { // filmDate = sdf.parse(date); // } catch (ParseException ex) { // } // if (jetzt != null && filmDate != null) { // ret = Math.round((jetzt.getTime() - filmDate.getTime()) / (1000)); // ret = Math.abs(ret); // } if (ret != 0) { Log.systemMeldung("Die Filmliste ist " + ret / 60 + " Minuten alt"); } return ret > sekunden; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override void meldungThreadUndFertig() { //wird erst ausgeführt wenn alle Threads beendet sind if (threads <= 0) { // sonst läuft noch was laufeSchon = false; } super.meldungThreadUndFertig(); } #location 5 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code @Override void meldungThreadUndFertig() { //wird erst ausgeführt wenn alle Threads beendet sind if (threads <= 0) { // sonst läuft noch was lSchon = false; } super.meldungThreadUndFertig(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void starten() { daten = new Daten(pfad); Daten.nogui = true; if (!userAgent.equals("")) { Daten.setUserAgentManuel(userAgent); } // Infos schreiben Log.startMeldungen(this.getClass().getName()); if (senderAllesLaden) { Log.systemMeldung("Programmstart: alles laden"); } else { Log.systemMeldung("Programmstart: nur update laden"); } Log.systemMeldung("ImportUrl: " + importUrl); Log.systemMeldung("Outputfile: " + output); Log.systemMeldung(""); Log.systemMeldung(""); Daten.filmeLaden.addAdListener(new ListenerFilmeLaden() { @Override public void fertig(ListenerFilmeLadenEvent event) { undTschuess(true /* exit */); } }); // laden was es schon gibt Daten.ioXmlFilmlisteLesen.filmlisteLesen(Daten.getBasisVerzeichnis() + Konstanten.XML_DATEI_FILME, false /* istUrl */, Daten.listeFilme); // das eigentliche Suchen der Filme bei den Sendern starten Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste); } #location 25 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void starten() { daten = new Daten(pfad); Daten.nogui = true; if (!userAgent.equals("")) { Daten.setUserAgentManuel(userAgent); } // Infos schreiben Log.startMeldungen(this.getClass().getName()); if (senderAllesLaden) { Log.systemMeldung("Programmstart: alles laden"); } else { Log.systemMeldung("Programmstart: nur update laden"); } Log.systemMeldung("ImportUrl: " + importUrl); Log.systemMeldung("Outputfile: " + output); Log.systemMeldung(""); Log.systemMeldung(""); Daten.filmeLaden.addAdListener(new ListenerFilmeLaden() { @Override public void fertig(ListenerFilmeLadenEvent event) { undTschuess(true /* exit */); } }); // laden was es schon gibt //Daten.ioXmlFilmlisteLesen.filmlisteLesen(Daten.getBasisVerzeichnis() + Konstanten.XML_DATEI_FILME, false /* istUrl */, Daten.listeFilme); new IoXmlFilmlisteLesen().standardFilmlisteLesen(); // das eigentliche Suchen der Filme bei den Sendern starten Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getPfadVlc() { /////////////////////// if (!Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR].equals("")) { return Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR]; } final String PFAD_LINUX_VLC = "/usr/bin/vlc"; final String PFAD_MAC_VLC = "/Applications/VLC.app/Contents/MacOS/VLC"; String pfad = ""; if (System.getProperty("os.name").toLowerCase().contains("windows")) { pfad = getWindowsVlcPath(); } else if (System.getProperty("os.name").toLowerCase().contains("linux")) { pfad = PFAD_LINUX_VLC; } else if (System.getProperty("os.name").toLowerCase().contains("mac")) { pfad = PFAD_MAC_VLC; } if (new File(pfad).exists()) { return pfad; } else { return ""; } } #location 13 #vulnerability type NULL_DEREFERENCE
#fixed code public static String getPfadVlc() { if (Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR].equals("")) { new DialogOk(null, true, new PanelProgrammPfade(), "Pfade Standardprogramme").setVisible(true); } return Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR]; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getPfadFlv() { ///////////////////// if (!Daten.system[Konstanten.SYSTEM_PFAD_FLVSTREAMER_NR].equals("")) { return Daten.system[Konstanten.SYSTEM_PFAD_FLVSTREAMER_NR]; } final String PFAD_LINUX_FLV = "/usr/bin/flvstreamer"; final String PFAD_WINDOWS_FLV = "bin\\flvstreamer_win32_latest.exe"; String pfad = ""; if (System.getProperty("os.name").toLowerCase().contains("windows")) { pfad = GuiFunktionenProgramme.getPathJar() + PFAD_WINDOWS_FLV; } else if (System.getProperty("os.name").toLowerCase().contains("linux")) { pfad = PFAD_LINUX_FLV; } if (new File(pfad).exists()) { return pfad; } else { return ""; } } #location 11 #vulnerability type NULL_DEREFERENCE
#fixed code public static String getPfadFlv() { if (Daten.system[Konstanten.SYSTEM_PFAD_FLVSTREAMER_NR].equals("")) { new DialogOk(null, true, new PanelProgrammPfade(), "Pfade Standardprogramme").setVisible(true); } return Daten.system[Konstanten.SYSTEM_PFAD_FLVSTREAMER_NR]; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void listeBauen() { //LinkedList mit den URLs aus dem Logfile bauen LineNumberReader in = null; File datei = null; try { datei = new File(Daten.getBasisVerzeichnis(false) + Konstanten.LOG_DATEI_DOWNLOAD_ABOS); if (datei.exists()) { in = new LineNumberReader(new InputStreamReader(new FileInputStream(datei))); String zeile; while ((zeile = in.readLine()) != null) { listeErledigteAbos.add(getUrlAusZeile(zeile)); } } } catch (Exception ex) { Log.fehlerMeldung(203632125, Log.FEHLER_ART_PROG, ErledigteAbos.class.getName(), ex); } finally { try { if (datei.exists()) { in.close(); } } catch (Exception ex) { Log.fehlerMeldung(898743697, Log.FEHLER_ART_PROG, ErledigteAbos.class.getName(), ex); } } } #location 19 #vulnerability type NULL_DEREFERENCE
#fixed code private void listeBauen() { //LinkedList mit den URLs aus dem Logfile bauen Path downloadAboFilePath = Daten.getDownloadAboFilePath(); //use Automatic Resource Management try (LineNumberReader in = new LineNumberReader(new InputStreamReader(Files.newInputStream(downloadAboFilePath)))) { String zeile; while ((zeile = in.readLine()) != null) listeErledigteAbos.add(getUrlAusZeile(zeile)); } catch (Exception ex) { //FIXME assign new error code! Log.fehlerMeldung(203632125, Log.FEHLER_ART_PROG, ErledigteAbos.class.getName(), ex); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getPfadVlc() { /////////////////////// if (!Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR].equals("")) { return Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR]; } final String PFAD_LINUX_VLC = "/usr/bin/vlc"; final String PFAD_MAC_VLC = "/Applications/VLC.app/Contents/MacOS/VLC"; String pfad = ""; if (System.getProperty("os.name").toLowerCase().contains("windows")) { pfad = getWindowsVlcPath(); } else if (System.getProperty("os.name").toLowerCase().contains("linux")) { pfad = PFAD_LINUX_VLC; } else if (System.getProperty("os.name").toLowerCase().contains("mac")) { pfad = PFAD_MAC_VLC; } if (new File(pfad).exists()) { return pfad; } else { return ""; } } #location 9 #vulnerability type NULL_DEREFERENCE
#fixed code public static String getPfadVlc() { if (Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR].equals("")) { new DialogOk(null, true, new PanelProgrammPfade(), "Pfade Standardprogramme").setVisible(true); } return Daten.system[Konstanten.SYSTEM_PFAD_VLC_NR]; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void metaDatenSchreiben() { // FilmlisteMetaDaten listeFilmeNeu.metaDaten = ListeFilme.newMetaDaten(); if (!Daten.filmeLaden.getStop() /* löschen */) { listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_DATUM_NR] = DatumZeit.getJetzt_ddMMyyyy_HHmm(); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_ZEIT_NR] = DatumZeit.getJetzt_HH_MM_SS(); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_DATUM_NR] = DatumZeit.getHeute_dd_MM_yyyy(); } else { listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_DATUM_NR] = ""; listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_ZEIT_NR] = ""; listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_DATUM_NR] = ""; } listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_ANZAHL_NR] = String.valueOf(listeFilmeNeu.size()); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_VERSION_NR] = Konstanten.VERSION; try { Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified()); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_PRGRAMM_NR] = "compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d); } catch (IOException ex) { Log.fehlerMeldung("FilmeSuchen.metaDatenSchreiben", ex); } } #location 16 #vulnerability type RESOURCE_LEAK
#fixed code private void metaDatenSchreiben() { // FilmlisteMetaDaten listeFilmeNeu.metaDaten = ListeFilme.newMetaDaten(); if (!Daten.filmeLaden.getStop() /* löschen */) { listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_DATUM_NR] = DatumZeit.getJetzt_ddMMyyyy_HHmm(); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_ZEIT_NR] = DatumZeit.getJetzt_HH_MM_SS(); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_DATUM_NR] = DatumZeit.getHeute_dd_MM_yyyy(); } else { listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_DATUM_NR] = ""; listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_ZEIT_NR] = ""; listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_NUR_DATUM_NR] = ""; } listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_ANZAHL_NR] = String.valueOf(listeFilmeNeu.size()); listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_VERSION_NR] = Konstanten.VERSION; listeFilmeNeu.metaDaten[ListeFilme.FILMLISTE_PRGRAMM_NR] = Log.getCompileDate(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getMusterPfadMplayer() { final String PFAD_LINUX = "/usr/bin/mplayer"; final String PFAD_MAC = "/opt/local/bin/mplayer"; String pfad = ""; if (System.getProperty("os.name").toLowerCase().contains("windows")) { pfad = getWindowsMplayerPath(); } else if (System.getProperty("os.name").toLowerCase().contains("linux")) { pfad = PFAD_LINUX; } else if (System.getProperty("os.name").toLowerCase().contains("mac")) { pfad = PFAD_MAC; } if (new File(pfad).exists()) { return pfad; } else { return ""; } } #location 9 #vulnerability type NULL_DEREFERENCE
#fixed code public static String getMusterPfadMplayer() { final String PFAD_LINUX = "/usr/bin/mplayer"; final String PFAD_MAC = "/opt/local/bin/mplayer"; final String PFAD_WIN_DEFAULT = "C:\\Program Files\\SMPlayer\\mplayer\\mplayer.exe"; final String PFAD_WIN = "\\SMPlayer\\mplayer\\mplayer.exe"; String pfad; switch (getOs()) { case OS_LINUX: pfad = PFAD_LINUX; break; case OS_MAC: pfad = PFAD_MAC; break; case OS_WIN_32BIT: case OS_WIN_64BIT: case OS_UNKNOWN: default: if (System.getenv("ProgramFiles") != null) { pfad = System.getenv("ProgramFiles") + PFAD_WIN; } else if (System.getenv("ProgramFiles(x86)") != null) { pfad = System.getenv("ProgramFiles(x86)") + PFAD_WIN; } else { pfad = PFAD_WIN_DEFAULT; } } if (!new File(pfad).exists()) { pfad = ""; } return pfad; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void ladenHttp(String filmWebsite, String thema, String alter) { // erst die Nummer suchen // >25420<4<165<23. Die b // <http://www.kikaplus.net/clients/kika/mediathek/previewpic/1355302530-f80b463888fd4602d925b2ef2c861928 9.jpg< final String MUSTER_BILD = "<http://www."; seiteHttp = getUrlIo.getUri(nameSenderMReader, filmWebsite, Konstanten.KODIERUNG_UTF, 1, seiteHttp, thema); String nummer, url, bild, urlFilm, titel; nummer = seiteHttp.extract(">", "<"); bild = seiteHttp.extract(MUSTER_BILD, "<"); if (!bild.isEmpty()) { bild = "http://www." + bild; } // die URL bauen: // http://www.kikaplus.net/clients/kika/kikaplus/hbbtv/index.php?cmd=video&age=10&id=25420&page=az if (!nummer.isEmpty()) { url = "http://www.kikaplus.net/clients/kika/kikaplus/hbbtv/index.php?cmd=video&age=" + alter + "&id=" + nummer + "&page=az"; seiteHttp = getUrlIo.getUri(nameSenderMReader, url, Konstanten.KODIERUNG_UTF, 1, seiteHttp, thema); final String MUSTER_URL = "var videofile = \""; final String MUSTER_TITEL = "var videotitle = \""; urlFilm = seiteHttp.extract(MUSTER_URL, "\""); titel = seiteHttp.extract(MUSTER_TITEL, "\""); if (!urlFilm.equals("")) { meldung(urlFilm); // DatenFilm(String ssender, String tthema, String filmWebsite, String ttitel, String uurl, String uurlRtmp, // String datum, String zeit, // long dauerSekunden, String description, String thumbnailUrl, String imageUrl, String[] keywords) { DatenFilm film = null; if ((film = istInFilmListe(nameSenderMReader, thema, titel)) != null) { film.addUrlKlein(urlFilm, ""); } else { // dann gibs ihn noch nicht addFilm(new DatenFilm(nameSenderMReader, thema, "http://www.kika.de/fernsehen/mediathek/index.shtml", titel, urlFilm, ""/* urlRtmp */, ""/*datum*/, ""/*zeit*/, 0, "", bild, "", new String[]{""})); } } else { Log.fehlerMeldung(-915263078, Log.FEHLER_ART_MREADER, "MediathekKika", "keine URL: " + filmWebsite); } } } #location 20 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code void addToListNormal() { //<strong style="margin-left:10px;">Sesamstraße präsentiert: Eine Möhre für Zwei</strong><br /> //<a style="margin-left:20px;" href="?programm=168&amp;id=14487&amp;ag=5" title="Sendung vom 10.10.2012" class="overlay_link">42. Ordnung ist das halbe Chaos</a><br /> //<a style="margin-left:20px;" href="?programm=168&amp;id=14485&amp;ag=5" title="Sendung vom 10.10.2012" class="overlay_link">41. Über den Wolken</a><br /> final String ADRESSE = "http://kikaplus.net/clients/kika/kikaplus/"; final String MUSTER_URL = "<a style=\"margin-left:20px;\" href=\""; final String MUSTER_THEMA = "<strong style=\"margin-left:10px;\">"; final String MUSTER_DATUM = "title=\"Sendung vom "; listeThemen.clear(); seite = new MVStringBuilder(Konstanten.STRING_BUFFER_START_BUFFER); seite = getUrlIo.getUri(nameSenderMReader, ADRESSE, Konstanten.KODIERUNG_UTF, 3, seite, "KiKA: Startseite"); int pos = 0; int pos1, pos2, stop, pDatum1, pDatum2, pTitel1, pTitel2; String url, thema, datum, titel; while ((pos = seite.indexOf(MUSTER_THEMA, pos)) != -1) { try { thema = ""; pos += MUSTER_THEMA.length(); stop = seite.indexOf(MUSTER_THEMA, pos); pos1 = pos; if ((pos2 = seite.indexOf("<", pos1)) != -1) { thema = seite.substring(pos1, pos2); } while ((pos1 = seite.indexOf(MUSTER_URL, pos1)) != -1) { titel = ""; datum = ""; if (stop != -1 && pos1 > stop) { // dann schon das nächste Thema break; } pos1 += MUSTER_URL.length(); if ((pos2 = seite.indexOf("\"", pos1)) != -1) { url = seite.substring(pos1, pos2); //if (!url.equals("")) { url = StringEscapeUtils.unescapeXml(url); if (!url.equals("") && !url.startsWith("http://") && !url.startsWith("/")) { // Datum if ((pDatum1 = seite.indexOf(MUSTER_DATUM, pos2)) != -1) { pDatum1 += MUSTER_DATUM.length(); if ((pDatum2 = seite.indexOf("\"", pDatum1)) != -1) { if (stop != -1 && pDatum1 < stop && pDatum2 < stop) { // dann schon das nächste Thema datum = seite.substring(pDatum1, pDatum2); } } } // Titel if ((pTitel1 = seite.indexOf(">", pos2)) != -1) { pTitel1 += 1; if ((pTitel2 = seite.indexOf("<", pTitel1)) != -1) { //if (stop != -1 && pTitel1 > stop && pTitel2 > stop) { if (stop != -1 && pTitel1 < stop && pTitel2 < stop) { titel = seite.substring(pTitel1, pTitel2); } } } // in die Liste eintragen String[] add = new String[]{ADRESSE + url, thema, titel, datum}; listeThemen.addUrl(add); } } } } catch (Exception ex) { Log.fehlerMeldung(-302025469, Log.FEHLER_ART_MREADER, "MediathekKiKA.addToList", ex, ""); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getMusterPfadMplayer() { final String PFAD_LINUX = "/usr/bin/mplayer"; final String PFAD_MAC = "/opt/local/bin/mplayer"; String pfad = ""; if (System.getProperty("os.name").toLowerCase().contains("windows")) { pfad = getWindowsMplayerPath(); } else if (System.getProperty("os.name").toLowerCase().contains("linux")) { pfad = PFAD_LINUX; } else if (System.getProperty("os.name").toLowerCase().contains("mac")) { pfad = PFAD_MAC; } if (new File(pfad).exists()) { return pfad; } else { return ""; } } #location 7 #vulnerability type NULL_DEREFERENCE
#fixed code public static String getMusterPfadMplayer() { final String PFAD_LINUX = "/usr/bin/mplayer"; final String PFAD_MAC = "/opt/local/bin/mplayer"; final String PFAD_WIN_DEFAULT = "C:\\Program Files\\SMPlayer\\mplayer\\mplayer.exe"; final String PFAD_WIN = "\\SMPlayer\\mplayer\\mplayer.exe"; String pfad; switch (getOs()) { case OS_LINUX: pfad = PFAD_LINUX; break; case OS_MAC: pfad = PFAD_MAC; break; case OS_WIN_32BIT: case OS_WIN_64BIT: case OS_UNKNOWN: default: if (System.getenv("ProgramFiles") != null) { pfad = System.getenv("ProgramFiles") + PFAD_WIN; } else if (System.getenv("ProgramFiles(x86)") != null) { pfad = System.getenv("ProgramFiles(x86)") + PFAD_WIN; } else { pfad = PFAD_WIN_DEFAULT; } } if (!new File(pfad).exists()) { pfad = ""; } return pfad; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void starten() { daten = new Daten(pfad); Daten.nogui = true; if (!userAgent.equals("")) { Daten.setUserAgentManuel(userAgent); } // Infos schreiben Log.startMeldungen(this.getClass().getName()); if (senderAllesLaden) { Log.systemMeldung("Programmstart: alles laden"); } else { Log.systemMeldung("Programmstart: nur update laden"); } Log.systemMeldung("ImportUrl: " + importUrl); Log.systemMeldung("Outputfile: " + output); Log.systemMeldung(""); Log.systemMeldung(""); Daten.filmeLaden.addAdListener(new ListenerFilmeLaden() { @Override public void fertig(ListenerFilmeLadenEvent event) { undTschuess(true /* exit */); } }); // laden was es schon gibt Daten.ioXmlFilmlisteLesen.filmlisteLesen(Daten.getBasisVerzeichnis() + Konstanten.XML_DATEI_FILME, false /* istUrl */, Daten.listeFilme); // das eigentliche Suchen der Filme bei den Sendern starten Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste); } #location 25 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void starten() { daten = new Daten(pfad); Daten.nogui = true; if (!userAgent.equals("")) { Daten.setUserAgentManuel(userAgent); } // Infos schreiben Log.startMeldungen(this.getClass().getName()); if (senderAllesLaden) { Log.systemMeldung("Programmstart: alles laden"); } else { Log.systemMeldung("Programmstart: nur update laden"); } Log.systemMeldung("ImportUrl: " + importUrl); Log.systemMeldung("Outputfile: " + output); Log.systemMeldung(""); Log.systemMeldung(""); Daten.filmeLaden.addAdListener(new ListenerFilmeLaden() { @Override public void fertig(ListenerFilmeLadenEvent event) { undTschuess(true /* exit */); } }); // laden was es schon gibt //Daten.ioXmlFilmlisteLesen.filmlisteLesen(Daten.getBasisVerzeichnis() + Konstanten.XML_DATEI_FILME, false /* istUrl */, Daten.listeFilme); new IoXmlFilmlisteLesen().standardFilmlisteLesen(); // das eigentliche Suchen der Filme bei den Sendern starten Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste); }
Below is the vulnerable code, please generate the patch based on the following information.