output
stringlengths 64
73.2k
| input
stringlengths 208
73.3k
| instruction
stringclasses 1
value |
---|---|---|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long lruCompactions()
{
return lruCompactions;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long size()
{
return size;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long lruCompactions()
{
return lruCompactions;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
int hashTableSize()
{
return table.size();
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long removeCount()
{
return removeCount;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long removeCount()
{
return removeCount;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long freeCapacity()
{
return freeCapacity;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
int hashTableSize()
{
return table.size();
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long rehashes()
{
return rehashes;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long evictedEntries()
{
return evictedEntries;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long missCount()
{
return missCount;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long putAddCount()
{
return putAddCount;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long evictedEntries()
{
return evictedEntries;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long putReplaceCount()
{
return putReplaceCount;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
void release()
{
table.release();
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long evictedEntries()
{
return evictedEntries;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#vulnerable code
long freeCapacity()
{
return freeCapacity;
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void start() throws InterruptedException {
thread = new Thread(this, "Fake Adb Server");
thread.setDaemon(true);
thread.start();
serverReady();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public String getHostVersion() throws IOException, JadbException {
try (Transport transport = createTransport()) {
transport.send("host:version");
transport.verifyResponse();
return transport.readString();
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void pull(RemoteFile remote, File local) throws IOException, JadbException {
try (FileOutputStream fileStream = new FileOutputStream(local)) {
pull(remote, fileStream);
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public String readString(int length) throws IOException {
byte[] responseBuffer = new byte[length];
dataInput.readFully(responseBuffer);
return new String(responseBuffer, StandardCharsets.UTF_8);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void start() throws InterruptedException {
thread = new Thread(this, "Fake Adb Server");
thread.setDaemon(true);
thread.start();
serverReady();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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());
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
}
}
|
#vulnerable code
public void load(File file) throws IOException {
InputStream in = new FileInputStream(file);
load(in);
in.close();
}
#location 5
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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)));
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void write(Object from, File target) throws IOException {
FileWriter writer = new FileWriter(target);
write(from, writer);
writer.close();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void write(Object from, OutputStream target) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(target, "UTF-8");
write(from, writer);
writer.flush();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void write(Object from, OutputStream target) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(target, "UTF-8");
write(from, writer);
writer.flush();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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];
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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];
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
@Override
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
try {
setBackground(null);
setForeground(null);
setFont(null);
setIcon(null);
setHorizontalAlignment(SwingConstants.LEADING);
super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
int r = table.convertRowIndexToModel(row);
int c = table.convertColumnIndexToModel(column);
String url = table.getModel().getValueAt(r, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
// Abos
boolean abo = !table.getModel().getValueAt(r, DatenDownload.DOWNLOAD_ABO_NR).equals("");
// Starts
Start s = ddaten.starterClass.getStart(url);
if (s != null) {
setColor(this, s, isSelected);
}
if (c == DatenDownload.DOWNLOAD_RESTZEIT_NR) {
this.setText(download.getTextRestzeit(ddaten, s));
} else if (c == DatenDownload.DOWNLOAD_PROGRESS_NR) {
int i = Integer.parseInt(download.arr[DatenDownload.DOWNLOAD_PROGRESS_NR]);
setHorizontalAlignment(SwingConstants.CENTER);
if (s != null && 1 < i && i < DatenDownload.PROGRESS_FERTIG) {
JProgressBar progressBar = new JProgressBar(0, 1000);
JPanel panel = new JPanel(new BorderLayout());
if (s != null) {
setColor(panel, s, isSelected);
setColor(progressBar, s, isSelected);
}
progressBar.setBorder(BorderFactory.createEmptyBorder());
progressBar.setStringPainted(true);
progressBar.setUI(new BasicProgressBarUI() {
@Override
protected Color getSelectionBackground() {
return UIManager.getDefaults().getColor("Table.foreground");
}
@Override
protected Color getSelectionForeground() {
return Color.white;
}
});
panel.add(progressBar);
panel.setBorder(BorderFactory.createEmptyBorder());
progressBar.setValue(i);
double d = i / 10.0;
progressBar.setString(Double.toString(d) + "%");
return panel;
} else {
this.setText(download.getTextProgress(ddaten, s));
}
} else if (c == DatenDownload.DOWNLOAD_ABO_NR) {
setFont(new java.awt.Font("Dialog", Font.BOLD, 12));
if (abo) {
setForeground(GuiKonstanten.ABO_FOREGROUND);
} else {
setForeground(GuiKonstanten.DOWNLOAD_FOREGROUND);
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/nein_12.png")));
setHorizontalAlignment(SwingConstants.CENTER);
}
} else if (c == DatenDownload.DOWNLOAD_PROGRAMM_RESTART_NR) {
boolean restart = download.isRestart();
setHorizontalAlignment(SwingConstants.CENTER);
if (restart) {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/ja_16.png")));
} else {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/nein_12.png")));
}
}
} catch (Exception ex) {
Log.fehlerMeldung(758200166, Log.FEHLER_ART_PROG, this.getClass().getName(), ex);
}
return this;
}
|
#vulnerable code
@Override
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
try {
setBackground(null);
setForeground(null);
setFont(null);
setIcon(null);
setHorizontalAlignment(SwingConstants.LEADING);
super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
int r = table.convertRowIndexToModel(row);
int c = table.convertColumnIndexToModel(column);
String url = table.getModel().getValueAt(r, DatenDownload.DOWNLOAD_URL_NR).toString();
// Abos
boolean abo = !table.getModel().getValueAt(r, DatenDownload.DOWNLOAD_ABO_NR).equals("");
// Starts
Start s = ddaten.starterClass.getStart(url);
if (s != null) {
setColor(this, s, isSelected);
if (c == DatenDownload.DOWNLOAD_RESTZEIT_NR) {
if (s.restSekunden > 0) {
if (s.restSekunden < 60) {
this.setText("< 1 Min.");
} else {
this.setText(Long.toString(s.restSekunden / 60) + " Min.");
}
} else {
this.setText("");
}
} else if (c == DatenDownload.DOWNLOAD_PROGRESS_NR) {
int i = Integer.parseInt(s.datenDownload.arr[DatenDownload.DOWNLOAD_PROGRESS_NR]);
setHorizontalAlignment(SwingConstants.CENTER);
if (i == -1) {
// noch nicht gestartet
this.setText("");
} else if (i == DatenDownload.PROGRESS_WARTEN) {
this.setText("warten");
} else if (i == DatenDownload.PROGRESS_GESTARTET) {
this.setText("gestartet");
} else if (1 < i && i < DatenDownload.PROGRESS_FERTIG) {
////// return new ProgressPanel(s).progressPanel();
JProgressBar progressBar = new JProgressBar(0, 1000);
JPanel panel = new JPanel(new BorderLayout());
setColor(panel, s, isSelected);
setColor(progressBar, s, isSelected);
progressBar.setBorder(BorderFactory.createEmptyBorder());
progressBar.setStringPainted(true);
progressBar.setUI(new BasicProgressBarUI() {
@Override
protected Color getSelectionBackground() {
return UIManager.getDefaults().getColor("Table.foreground");
}
@Override
protected Color getSelectionForeground() {
return Color.white;
}
});
panel.add(progressBar);
panel.setBorder(BorderFactory.createEmptyBorder());
progressBar.setValue(i);
double d = i / 10.0;
progressBar.setString(Double.toString(d) + "%");
return panel;
} else if (i == DatenDownload.PROGRESS_FERTIG) {
if (s != null) {
if (s.status == Start.STATUS_ERR) {
this.setText("fehlerhaft");
} else {
this.setText("fertig");
}
} else {
this.setText("fertig");
}
}
}
} else {
if (c == DatenDownload.DOWNLOAD_PROGRESS_NR) {
this.setText("");
}
}
if (c == DatenDownload.DOWNLOAD_ABO_NR) {
setFont(new java.awt.Font("Dialog", Font.BOLD, 12));
if (abo) {
setForeground(GuiKonstanten.ABO_FOREGROUND);
} else {
setForeground(GuiKonstanten.DOWNLOAD_FOREGROUND);
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/nein_12.png")));
setHorizontalAlignment(SwingConstants.CENTER);
}
}
if (c == DatenDownload.DOWNLOAD_PROGRAMM_RESTART_NR) {
boolean restart = ddaten.listeDownloads.getDownloadByUrl(url).isRestart();
setHorizontalAlignment(SwingConstants.CENTER);
if (restart) {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/ja_16.png")));
} else {
setIcon(new javax.swing.ImageIcon(getClass().getResource("/mediathek/res/nein_12.png")));
}
}
} catch (Exception ex) {
Log.fehlerMeldung(758200166, Log.FEHLER_ART_PROG, this.getClass().getName(), ex);
}
return this;
}
#location 99
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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 32
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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];
}
|
#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 9
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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();
if (!senderLoeschen.isEmpty()) {
senderLoeschenUndExit();
} else {
// das eigentliche Suchen der Filme bei den Sendern starten
Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste);
}
}
|
#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);
new IoXmlFilmlisteLesen().standardFilmlisteLesen();
if (!senderLoeschen.isEmpty()) {
senderLoeschenUndExit();
}
// das eigentliche Suchen der Filme bei den Sendern starten
Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste);
}
#location 28
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = tabelle.getSelectedRows();
if (rows.length > 0) {
String[] urls = new String[rows.length];
for (int i = 0; i < rows.length; ++i) {
urls[i] = tabelle.getModel().getValueAt(tabelle.convertRowIndexToModel(rows[i]), DatenDownload.DOWNLOAD_URL_NR).toString();
}
for (int i = 0; i < urls.length; ++i) {
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(urls[i]);
if (download == null) {
// wie kann das sein??
Log.debugMeldung("Gits ja gar nicht");
} else {
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR], urls[i]);
}
ddaten.listeDownloads.delDownloadByUrl(urls[i]);
}// if (dauerhaft) {
ddaten.starterClass.filmLoeschen(urls[i]);
}
}
} else {
new HinweisKeineAuswahl().zeigen();
}
}
|
#vulnerable code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = tabelle.getSelectedRows();
if (rows.length > 0) {
for (int i = rows.length - 1; i >= 0; --i) {
int delRow = tabelle.convertRowIndexToModel(rows[i]);
String url = tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR],
url);
}
ddaten.listeDownloads.delDownloadByUrl(url);
}
ddaten.starterClass.filmLoeschen(tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString());
((TModelDownload) tabelle.getModel()).removeRow(delRow);
}
setInfo();
} else {
new HinweisKeineAuswahl().zeigen();
}
}
#location 9
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getMusterPfadVlc() {
final String PFAD_LINUX_VLC = "/usr/bin/vlc";
final String PFAD_MAC_VLC = "/Applications/VLC.app/Contents/MacOS/VLC";
final String PFAD_WIN_DEFAULT = "C:\\Programme\\VideoLAN\\VLC\\vlc.exe";
final String PFAD_WIN = "\\VideoLAN\\VLC\\vlc.exe";
String pfad;
switch (getOs()) {
case OS_LINUX:
pfad = PFAD_LINUX_VLC;
break;
case OS_MAC:
pfad = PFAD_MAC_VLC;
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;
}
|
#vulnerable code
public static String getMusterPfadVlc() {
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 5
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void meldenFertig(String sender) {
//wird ausgeführt wenn Sender beendet ist
int MAX_SENDER = 15, MAX1 = 24, MAX2 = 30;
Log.systemMeldung("Fertig " + sender + ": " + DatumZeit.getJetzt_HH_MM_SS());
RunSender run = listeSenderLaufen.senderFertig(sender);
if (run != null) {
// Zeile 1
String zeile = "==================================================================================================================";
fertigMeldung.add(zeile);
zeile = textLaenge(MAX_SENDER, run.sender);
zeile += textLaenge(MAX1, "Laufzeit[Min.]: " + run.getLaufzeitMinuten());
zeile += textLaenge(MAX1, " Seiten: " + GetUrl.getSeitenZaehler(GetUrl.LISTE_SEITEN_ZAEHLER, run.sender));
String nameFilmliste[] = getMReaderNameSenderMreader(run.sender).getNameSenderFilmliste();
if (nameFilmliste.length == 1) {
zeile += "Filme: " + listeFilmeNeu.countSender(nameFilmliste[0]);
} else {
for (int i = 0; i < nameFilmliste.length; i++) {
zeile += "Filme [" + nameFilmliste[i] + "]: " + listeFilmeNeu.countSender(nameFilmliste[i]) + " ";
}
}
fertigMeldung.add(zeile);
// Zeile 2
zeile = textLaenge(MAX_SENDER, "");
zeile += textLaenge(MAX1, " Ladefehler: " + GetUrl.getSeitenZaehler(GetUrl.LISTE_SEITEN_ZAEHLER_FEHlER, run.sender));
zeile += textLaenge(MAX1, "Fehlversuche: " + GetUrl.getSeitenZaehler(GetUrl.LISTE_SEITEN_ZAEHLER_FEHLERVERSUCHE, run.sender));
zeile += textLaenge(MAX2, "Wartezeit Fehler[s]: " + GetUrl.getSeitenZaehler(GetUrl.LISTE_SEITEN_ZAEHLER_WARTEZEIT_FEHLVERSUCHE, run.sender));
String groesse = (GetUrl.getSeitenZaehler(GetUrl.LISTE_SUMME_BYTE, run.sender) == 0) ? "<1" : Long.toString(GetUrl.getSeitenZaehler(GetUrl.LISTE_SUMME_BYTE, run.sender));
zeile += textLaenge(MAX1, "Daten[MByte]: " + groesse);
fertigMeldung.add(zeile);
}
// wird einmal aufgerufen, wenn alle Sender fertig sind
if (listeSenderLaufen.listeFertig()) {
listeFilmeNeu.sort();
if (!allesLaden) {
// alte Filme eintragen
listeFilmeNeu.updateListe(listeFilmeAlt, true /* über den Index vergleichen */);
}
listeFilmeAlt = null; // brauchmer nicht mehr
metaDatenSchreiben();
stopZeit = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
int minuten;
try {
minuten = Math.round((stopZeit.getTime() - startZeit.getTime()) / (1000 * 60));
} catch (Exception ex) {
minuten = -1;
}
Log.systemMeldung("");
Log.systemMeldung("==================================================================================================================");
Log.systemMeldung("Sender ===========================================================================================================");
Log.systemMeldung(fertigMeldung.toArray(new String[0]));
Log.systemMeldung("==================================================================================================================");
Log.systemMeldung("");
Log.systemMeldung(" Seiten geladen: " + GetUrl.getSeitenZaehler(GetUrl.LISTE_SEITEN_ZAEHLER));
String groesse = (GetUrl.getSeitenZaehler(GetUrl.LISTE_SUMME_BYTE) == 0) ? "<1" : Long.toString(GetUrl.getSeitenZaehler(GetUrl.LISTE_SUMME_BYTE, run.sender));
Log.systemMeldung("Summe geladen[MByte]: " + groesse);
Log.systemMeldung(" --> Start: " + sdf.format(startZeit));
Log.systemMeldung(" --> Ende: " + sdf.format(stopZeit));
Log.systemMeldung(" --> Dauer[Min]: " + (minuten == 0 ? "<1" : minuten));
Log.systemMeldung("");
Log.systemMeldung("==================================================================================================================");
Log.systemMeldung("==================================================================================================================");
notifyFertig(new FilmListenerElement(sender, "", listeSenderLaufen.getMax(), listeSenderLaufen.getProgress()));
} else {
//nur ein Sender fertig
notifyProgress(new FilmListenerElement(sender, "", listeSenderLaufen.getMax(), listeSenderLaufen.getProgress()));
}
}
|
#vulnerable code
public void meldenFertig(String sender) {
//wird ausgeführt wenn Sender beendet ist
int MAX_SENDER = 25, MAX1 = 22, MAX2 = 15, MAX3 = 20, MAX4 = 30;
Log.systemMeldung("Fertig " + sender + ": " + DatumZeit.getJetzt_HH_MM_SS());
RunSender run = listeSenderLaufen.senderFertig(sender);
if (run != null) {
String zeile = "";
zeile += textLaenge(MAX_SENDER, "Sender: " + run.sender);
zeile += textLaenge(MAX1, " Laufzeit: " + run.getLaufzeitMinuten() + " Min.");
zeile += textLaenge(MAX2, " Seiten: " + GetUrl.getSeitenZaehler(run.sender));
zeile += textLaenge(MAX3, " Ladefehler: " + GetUrl.getSeitenZaehlerFehler(run.sender));
zeile += textLaenge(MAX3, " Fehlversuche: " + GetUrl.getSeitenZaehlerFehlerVersuche(run.sender));
zeile += textLaenge(MAX4, " Wartezeit Fehler[s]: " + GetUrl.getSeitenZaehlerWartezeitFehlerVersuche(run.sender));
String nameFilmliste[] = getMReaderNameSenderMreader(run.sender).getNameSenderFilmliste();
if (nameFilmliste.length == 1) {
zeile += textLaenge(MAX3, " Filme: " + listeFilmeNeu.countSender(nameFilmliste[0]));
fertigMeldung.add(zeile);
} else {
fertigMeldung.add(zeile);
for (int i = 0; i < nameFilmliste.length; i++) {
zeile = " --> Filme [" + nameFilmliste[i] + "]: " + listeFilmeNeu.countSender(nameFilmliste[i]);
fertigMeldung.add(zeile);
}
}
}
// wird einmal aufgerufen, wenn alle Sender fertig sind
if (listeSenderLaufen.listeFertig()) {
listeFilmeNeu.sort();
if (!allesLaden) {
// alte Filme eintragen
listeFilmeNeu.updateListe(listeFilmeAlt, true /* über den Index vergleichen */);
}
listeFilmeAlt = null; // brauchmer nicht mehr
metaDatenSchreiben();
stopZeit = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
int minuten;
try {
minuten = Math.round((stopZeit.getTime() - startZeit.getTime()) / (1000 * 60));
} catch (Exception ex) {
minuten = -1;
}
Log.systemMeldung("");
Log.systemMeldung("============================================================");
Log.systemMeldung("============================================================");
Log.systemMeldung("");
Log.systemMeldung(fertigMeldung.toArray(new String[0]));
Log.systemMeldung("");
Log.systemMeldung("============================================================");
Log.systemMeldung("");
Log.systemMeldung("Seiten geladen: " + GetUrl.getSeitenZaehler());
Log.systemMeldung("Summe geladen: " + GetUrl.getSumByte() / 1024 / 1024 + " MByte");
Log.systemMeldung(" --> Start: " + sdf.format(startZeit));
Log.systemMeldung(" --> Ende: " + sdf.format(stopZeit));
Log.systemMeldung(" --> Dauer[Min]: " + (minuten == 0 ? "<1" : minuten));
Log.systemMeldung("");
Log.systemMeldung("============================================================");
Log.systemMeldung("============================================================");
notifyFertig(new FilmListenerElement(sender, "", listeSenderLaufen.getMax(), listeSenderLaufen.getProgress()));
} else {
//nur ein Sender fertig
notifyProgress(new FilmListenerElement(sender, "", listeSenderLaufen.getMax(), listeSenderLaufen.getProgress()));
}
}
#location 53
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getMusterPfadFlv() {
final String PFAD_LINUX_FLV = "/usr/bin/flvstreamer";
final String PFAD_WINDOWS_FLV = "bin\\flvstreamer_win32_latest.exe";
final String PFAD_MAC_FLV = "bin\\flvstreamer_macosx_intel_32bit_latest";
String pfad;
switch (getOs()) {
case OS_LINUX:
pfad = PFAD_LINUX_FLV;
break;
case OS_MAC:
pfad = Funktionen.getPathJar() + PFAD_MAC_FLV;
break;
case OS_WIN_32BIT:
case OS_WIN_64BIT:
case OS_UNKNOWN:
default:
pfad = Funktionen.getPathJar() + PFAD_WINDOWS_FLV;
}
if (new File(pfad).exists()) {
return pfad;
} else {
return "";
}
}
|
#vulnerable code
public static String getMusterPfadFlv() {
final String PFAD_LINUX_FLV = "/usr/bin/flvstreamer";
final String PFAD_WINDOWS_FLV = "bin\\flvstreamer_win32_latest.exe";
final String PFAD_MAC_FLV = "bin\\flvstreamer_macosx_intel_32bit_latest";
String pfad = "";
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
pfad = Funktionen.getPathJar() + PFAD_WINDOWS_FLV;
} else if (System.getProperty("os.name").toLowerCase().contains("linux")) {
pfad = PFAD_LINUX_FLV;
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
pfad = Funktionen.getPathJar() + PFAD_MAC_FLV;
}
if (new File(pfad).exists()) {
return pfad;
} else {
return "";
}
}
#location 10
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getMusterPfadFlv() {
final String PFAD_LINUX_FLV = "/usr/bin/flvstreamer";
final String PFAD_WINDOWS_FLV = "bin\\flvstreamer_win32_latest.exe";
final String PFAD_MAC_FLV = "bin\\flvstreamer_macosx_intel_32bit_latest";
String pfad;
switch (getOs()) {
case OS_LINUX:
pfad = PFAD_LINUX_FLV;
break;
case OS_MAC:
pfad = Funktionen.getPathJar() + PFAD_MAC_FLV;
break;
case OS_WIN_32BIT:
case OS_WIN_64BIT:
case OS_UNKNOWN:
default:
pfad = Funktionen.getPathJar() + PFAD_WINDOWS_FLV;
}
if (new File(pfad).exists()) {
return pfad;
} else {
return "";
}
}
|
#vulnerable code
public static String getMusterPfadFlv() {
final String PFAD_LINUX_FLV = "/usr/bin/flvstreamer";
final String PFAD_WINDOWS_FLV = "bin\\flvstreamer_win32_latest.exe";
final String PFAD_MAC_FLV = "bin\\flvstreamer_macosx_intel_32bit_latest";
String pfad = "";
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
pfad = Funktionen.getPathJar() + PFAD_WINDOWS_FLV;
} else if (System.getProperty("os.name").toLowerCase().contains("linux")) {
pfad = PFAD_LINUX_FLV;
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
pfad = Funktionen.getPathJar() + PFAD_MAC_FLV;
}
if (new File(pfad).exists()) {
return pfad;
} else {
return "";
}
}
#location 6
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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 21
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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);
}
|
#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);
new IoXmlFilmlisteLesen().standardFilmlisteLesen();
if (!senderLoeschen.isEmpty()) {
senderLoeschenUndExit();
} else {
// das eigentliche Suchen der Filme bei den Sendern starten
Daten.filmeLaden.filmeBeimSenderSuchen(Daten.listeFilme, senderAllesLaden, updateFilmliste);
}
}
#location 2
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = tabelle.getSelectedRows();
if (rows.length > 0) {
for (int i = rows.length - 1; i >= 0; --i) {
int delRow = tabelle.convertRowIndexToModel(rows[i]);
String url = tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR],
url);
}
ddaten.listeDownloads.delDownloadByUrl(url);
}
ddaten.starterClass.filmLoeschen(tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString());
((TModelDownload) tabelle.getModel()).removeRow(delRow);
}
setInfo();
} else {
new HinweisKeineAuswahl().zeigen();
}
}
|
#vulnerable code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = jTable1.getSelectedRows();
if (rows.length > 0) {
for (int i = rows.length - 1; i >= 0; --i) {
int delRow = jTable1.convertRowIndexToModel(rows[i]);
String url = jTable1.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR],
url);
}
ddaten.listeDownloads.delDownloadByUrl(url);
}
ddaten.starterClass.filmLoeschen(jTable1.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString());
((TModelDownload) jTable1.getModel()).removeRow(delRow);
}
setInfo();
} else {
new HinweisKeineAuswahl().zeigen();
}
}
#location 6
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static synchronized void startMeldungen(String classname) {
versionsMeldungen(classname);
Log.systemMeldung("Programmpfad: " + GuiFunktionenProgramme.getPathJar());
Log.systemMeldung("Verzeichnis Einstellungen: " + Daten.getBasisVerzeichnis());
Log.systemMeldung("Useragent: " + Daten.getUserAgent());
Log.systemMeldung("###########################################################");
Log.systemMeldung("");
Log.systemMeldung("");
}
|
#vulnerable code
public static synchronized void startMeldungen(String classname) {
Log.systemMeldung("###########################################################");
try {
//Version
Log.systemMeldung(Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION);
Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
Log.systemMeldung("Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d));
} catch (IOException ex) {
}
Log.systemMeldung("Klassenname: " + classname);
Log.systemMeldung("");
Log.systemMeldung("Programmpfad: " + GuiFunktionenProgramme.getPathJar());
Log.systemMeldung("Verzeichnis Einstellungen: " + Daten.getBasisVerzeichnis());
Log.systemMeldung("Useragent: " + Daten.getUserAgent());
Log.systemMeldung("");
long totalMem = Runtime.getRuntime().totalMemory();
Log.systemMeldung("totalMemory: " + totalMem / (1024L * 1024L) + " MB");
long maxMem = Runtime.getRuntime().maxMemory();
Log.systemMeldung("maxMemory: " + maxMem / (1024L * 1024L) + " MB");
long freeMem = Runtime.getRuntime().freeMemory();
Log.systemMeldung("freeMemory: " + freeMem / (1024L * 1024L) + " MB");
Log.systemMeldung("###########################################################");
}
#location 6
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getPfadScript() {
String pfadScript;
final String PFAD_LINUX_SCRIPT = "bin/flv.sh";
final String PFAD_WINDOWS_SCRIPT = "bin\\flv.bat";
switch (getOs()) {
case OS_LINUX:
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
break;
case OS_MAC:
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
break;
case OS_WIN_32BIT:
case OS_WIN_64BIT:
case OS_UNKNOWN:
default:
pfadScript = Funktionen.getPathJar() + PFAD_WINDOWS_SCRIPT;
}
return pfadScript;
}
|
#vulnerable code
public static String getPfadScript() {
String pfadScript;
final String PFAD_LINUX_SCRIPT = "bin/flv.sh";
final String PFAD_WINDOWS_SCRIPT = "bin\\flv.bat";
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
} else {
pfadScript = Funktionen.getPathJar() + PFAD_WINDOWS_SCRIPT;
}
return pfadScript;
}
#location 7
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public synchronized boolean zeileSchreiben(ArrayList<String[]> list) {
boolean ret = false;
String text;
String zeit = DatumZeit.getHeute_dd_MM_yyyy();
String thema, titel, url;
try (OutputStreamWriter writer = new OutputStreamWriter(Files.newOutputStream(Daten.getDownloadAboFilePath()))) {
for (String[] a : list) {
thema = a[0];
titel = a[1];
url = a[2];
listeErledigteAbos.add(url);
thema = GuiFunktionen.textLaenge(25, putzen(thema), false /* mitte */, false /*addVorne*/);
titel = GuiFunktionen.textLaenge(30, putzen(titel), false /* mitte */, false /*addVorne*/);
text = zeit + PAUSE + thema + PAUSE + titel + TRENNER + url + "\n";
writer.write(text);
ret = true;
}
} catch (Exception ex) {
ret = false;
Log.fehlerMeldung(945258023, Log.FEHLER_ART_PROG, "LogDownload.zeileSchreiben-1", ex);
}
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_ERLEDIGTE_ABOS, ErledigteAbos.class.getSimpleName());
return ret;
}
|
#vulnerable code
public synchronized boolean zeileSchreiben(ArrayList<String[]> list) {
boolean ret = false;
String text;
String zeit = DatumZeit.getHeute_dd_MM_yyyy();
String thema, titel, url;
OutputStreamWriter writer = null;
File f = new File(Daten.getBasisVerzeichnis(true) + Konstanten.LOG_DATEI_DOWNLOAD_ABOS);
try {
writer = new OutputStreamWriter(new FileOutputStream(f, true));
for (String[] a : list) {
thema = a[0];
titel = a[1];
url = a[2];
listeErledigteAbos.add(url);
thema = GuiFunktionen.textLaenge(25, putzen(thema), false /* mitte */, false /*addVorne*/);
titel = GuiFunktionen.textLaenge(30, putzen(titel), false /* mitte */, false /*addVorne*/);
text = zeit + PAUSE + thema + PAUSE + titel + TRENNER + url + "\n";
writer.write(text);
ret = true;
}
// writer.close();
} catch (Exception ex) {
ret = false;
Log.fehlerMeldung(945258023, Log.FEHLER_ART_PROG, "LogDownload.zeileSchreiben-1", ex);
} finally {
try {
writer.close();
} catch (Exception ex) {
}
}
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_ERLEDIGTE_ABOS, ErledigteAbos.class.getSimpleName());
return ret;
}
#location 27
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getCompileDate() {
// String ret = "";
// try {
// Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
// ret = Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d);
// } catch (Exception ex) {
// Log.fehlerMeldung(569614756, "Log.getCompileDate: ", ex);
// }
// return ret;
final ResourceBundle rb;
String propToken = "BUILDDATE";
String msg = "";
try {
ResourceBundle.clearCache();
rb = ResourceBundle.getBundle("version");
msg = rb.getString(propToken);
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println("Token " + propToken + " not in Propertyfile!");
}
return Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + msg;
}
|
#vulnerable code
public static String getCompileDate() {
String ret = "";
try {
Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
ret = Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d);
} catch (Exception ex) {
Log.fehlerMeldung(569614756, "Log.getCompileDate: ", ex);
}
return ret;
}
#location 4
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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 8
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void updateSender(String nameSenderFilmliste, ListeFilme alteListe) {
// nur für den Mauskontext "Sender aktualisieren"
// allesLaden = false;
initStart(alteListe);
MediathekReader reader = getMReaderNameSenderFilmliste(nameSenderFilmliste);
if (reader != null) {
new Thread(reader).start();
}
}
|
#vulnerable code
public void updateSender(String nameSenderFilmliste, ListeFilme alteListe) {
// nur für den Mauskontext "Sender aktualisieren"
allesLaden = false;
initStart(alteListe);
MediathekReader reader = getMReaderNameSenderFilmliste(nameSenderFilmliste);
if (reader != null) {
new Thread(reader).start();
}
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static ListePset getStandardprogramme(DDaten ddaten) {
ListePset pSet;
InputStream datei;
switch (getOs()) {
case OS_LINUX:
datei = new GetFile().getPsetVorlageLinux();
break;
case OS_MAC:
datei = new GetFile().getPsetVorlageMac();
break;
case OS_WIN_32BIT:
case OS_WIN_64BIT:
case OS_UNKNOWN:
default:
datei = new GetFile().getPsetVorlageWindows();
}
// Standardgruppen laden
pSet = IoXmlLesen.importPset(datei, true);
return pSet;
}
|
#vulnerable code
public static ListePset getStandardprogramme(DDaten ddaten) {
ListePset pSet;
InputStream datei;
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
datei = new GetFile().getPsetVorlageLinux();
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
datei = new GetFile().getPsetVorlageMac();
} else {
datei = new GetFile().getPsetVorlageWindows();
}
// Standardgruppen laden
pSet = IoXmlLesen.importPset(datei, true);
return pSet;
}
#location 6
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static boolean isLeopard() {
return SystemInfo.isMacOSX() && SystemInfo.getOSVersion().startsWith("10.5");
}
|
#vulnerable code
public static boolean isLeopard() {
return isMac() && getOsVersion().startsWith("10.5");
}
#location 2
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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 9
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public synchronized boolean zeileSchreiben(String thema, String titel, String url) {
boolean ret = false;
String text;
listeErledigteAbos.add(url);
//Automatic Resource Management
try (OutputStreamWriter writer = new OutputStreamWriter(Files.newOutputStream(Daten.getDownloadAboFilePath()))) {
thema = GuiFunktionen.textLaenge(25, putzen(thema), false /* mitte */, false /*addVorne*/);
titel = GuiFunktionen.textLaenge(30, putzen(titel), false /* mitte */, false /*addVorne*/);
text = DatumZeit.getHeute_dd_MM_yyyy() + PAUSE + thema + PAUSE + titel + TRENNER + url + "\n";
writer.write(text);
ret = true;
} catch (Exception ex) {
Log.fehlerMeldung(945258023, Log.FEHLER_ART_PROG, "LogDownload.zeileSchreiben-1", ex);
}
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_ERLEDIGTE_ABOS, ErledigteAbos.class.getSimpleName());
return ret;
}
|
#vulnerable code
public synchronized boolean zeileSchreiben(String thema, String titel, String url) {
boolean ret = false;
String text;
listeErledigteAbos.add(url);
File f = new File(Daten.getBasisVerzeichnis(true) + Konstanten.LOG_DATEI_DOWNLOAD_ABOS);
if (f != null) {
OutputStreamWriter writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(f, true));
thema = GuiFunktionen.textLaenge(25, putzen(thema), false /* mitte */, false /*addVorne*/);
titel = GuiFunktionen.textLaenge(30, putzen(titel), false /* mitte */, false /*addVorne*/);
text = DatumZeit.getHeute_dd_MM_yyyy() + PAUSE + thema + PAUSE + titel + TRENNER + url + "\n";
writer.write(text);
writer.close();
ret = true;
} catch (Exception ex) {
Log.fehlerMeldung(945258023, Log.FEHLER_ART_PROG, "LogDownload.zeileSchreiben-1", ex);
} finally {
try {
writer.close();
} catch (Exception ex) {
}
}
}
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_ERLEDIGTE_ABOS, ErledigteAbos.class.getSimpleName());
return ret;
}
#location 14
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = tabelle.getSelectedRows();
if (rows.length > 0) {
for (int i = rows.length - 1; i >= 0; --i) {
int delRow = tabelle.convertRowIndexToModel(rows[i]);
String url = tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR],
url);
}
ddaten.listeDownloads.delDownloadByUrl(url);
}
ddaten.starterClass.filmLoeschen(tabelle.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString());
((TModelDownload) tabelle.getModel()).removeRow(delRow);
}
setInfo();
} else {
new HinweisKeineAuswahl().zeigen();
}
}
|
#vulnerable code
private void downloadLoeschen(boolean dauerhaft) {
int rows[] = jTable1.getSelectedRows();
if (rows.length > 0) {
for (int i = rows.length - 1; i >= 0; --i) {
int delRow = jTable1.convertRowIndexToModel(rows[i]);
String url = jTable1.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString();
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (dauerhaft) {
if (download.istAbo()) {
// ein Abo wird zusätzlich ins Logfile geschrieben
ddaten.erledigteAbos.zeileSchreiben(download.arr[DatenDownload.DOWNLOAD_THEMA_NR],
download.arr[DatenDownload.DOWNLOAD_TITEL_NR],
url);
}
ddaten.listeDownloads.delDownloadByUrl(url);
}
ddaten.starterClass.filmLoeschen(jTable1.getModel().getValueAt(delRow, DatenDownload.DOWNLOAD_URL_NR).toString());
((TModelDownload) jTable1.getModel()).removeRow(delRow);
}
setInfo();
} else {
new HinweisKeineAuswahl().zeigen();
}
}
#location 17
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static synchronized void versionsMeldungen(String classname) {
Log.systemMeldung("###########################################################");
long totalMem = Runtime.getRuntime().totalMemory();
Log.systemMeldung("totalMemory: " + totalMem / (1024L * 1024L) + " MB");
long maxMem = Runtime.getRuntime().maxMemory();
Log.systemMeldung("maxMemory: " + maxMem / (1024L * 1024L) + " MB");
long freeMem = Runtime.getRuntime().freeMemory();
Log.systemMeldung("freeMemory: " + freeMem / (1024L * 1024L) + " MB");
Log.systemMeldung("###########################################################");
//Version
Log.systemMeldung(getCompileDate());
Log.systemMeldung("Klassenname: " + classname);
Log.systemMeldung("###########################################################");
}
|
#vulnerable code
public static synchronized void versionsMeldungen(String classname) {
Log.systemMeldung("###########################################################");
long totalMem = Runtime.getRuntime().totalMemory();
Log.systemMeldung("totalMemory: " + totalMem / (1024L * 1024L) + " MB");
long maxMem = Runtime.getRuntime().maxMemory();
Log.systemMeldung("maxMemory: " + maxMem / (1024L * 1024L) + " MB");
long freeMem = Runtime.getRuntime().freeMemory();
Log.systemMeldung("freeMemory: " + freeMem / (1024L * 1024L) + " MB");
Log.systemMeldung("###########################################################");
try {
//Version
Log.systemMeldung(Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION);
Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
Log.systemMeldung("Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d));
} catch (IOException ex) {
}
Log.systemMeldung("Klassenname: " + classname);
Log.systemMeldung("###########################################################");
}
#location 13
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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;
}
|
#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 5
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getPfadScript() {
String pfadScript;
final String PFAD_LINUX_SCRIPT = "bin/flv.sh";
final String PFAD_WINDOWS_SCRIPT = "bin\\flv.bat";
switch (getOs()) {
case OS_LINUX:
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
break;
case OS_MAC:
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
break;
case OS_WIN_32BIT:
case OS_WIN_64BIT:
case OS_UNKNOWN:
default:
pfadScript = Funktionen.getPathJar() + PFAD_WINDOWS_SCRIPT;
}
return pfadScript;
}
|
#vulnerable code
public static String getPfadScript() {
String pfadScript;
final String PFAD_LINUX_SCRIPT = "bin/flv.sh";
final String PFAD_WINDOWS_SCRIPT = "bin\\flv.bat";
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
} else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
pfadScript = Funktionen.getPathJar() + PFAD_LINUX_SCRIPT;
} else {
pfadScript = Funktionen.getPathJar() + PFAD_WINDOWS_SCRIPT;
}
return pfadScript;
}
#location 5
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void filmStartenWiederholenStoppen(boolean alle, boolean starten /* starten/wiederstarten oder stoppen */) {
// bezieht sich immer auf "alle" oder nur die markierten
// Film der noch keinen Starts hat wird gestartet
// Film dessen Start schon auf fertig/fehler steht wird wieder gestartet
// bei !starten wird der Film gestoppt
String[] urls;
ArrayList<DatenDownload> arrayDownload = new ArrayList<DatenDownload>();
// ==========================
// erst mal die URLs sammeln
if (alle) {
urls = new String[tabelle.getRowCount()];
for (int i = 0; i < tabelle.getRowCount(); ++i) {
urls[i] = tabelle.getModel().getValueAt(i, DatenDownload.DOWNLOAD_URL_NR).toString();
}
} else {
int[] rows = tabelle.getSelectedRows();
urls = new String[rows.length];
if (rows.length >= 0) {
for (int i = 0; i < rows.length; i++) {
int row = tabelle.convertRowIndexToModel(rows[i]);
urls[i] = tabelle.getModel().getValueAt(row, DatenDownload.DOWNLOAD_URL_NR).toString();
}
} else {
new HinweisKeineAuswahl().zeigen(parentComponent);
}
}
// ========================
// und jetzt abarbeiten
for (String url : urls) {
Start s = ddaten.starterClass.getStart(url);
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (starten) {
// --------------
// starten
if (s != null) {
if (s.status > Start.STATUS_RUN) {
// wenn er noch läuft gibts nix
// wenn er schon fertig ist, erst mal fragen vor dem erneuten Starten
int a = JOptionPane.showConfirmDialog(parentComponent, "Film nochmal starten? ==> " + s.datenDownload.arr[DatenDownload.DOWNLOAD_TITEL_NR], "Fertiger Download", JOptionPane.YES_NO_OPTION);
if (a != JOptionPane.YES_OPTION) {
// weiter mit der nächsten URL
continue;
}
ddaten.starterClass.filmLoeschen(url);
if (s.datenDownload.istAbo()) {
// bei Abos Url auch aus dem Logfile löschen, der Film ist damit wieder auf "Anfang"
ddaten.erledigteAbos.urlAusLogfileLoeschen(url);
}
}
}
arrayDownload.add(download);
} else {
// ---------------
// stoppen
if (s != null) {
// wenn kein s -> dann gibts auch nichts zum stoppen oder wieder-starten
if (s.status <= Start.STATUS_RUN) {
// löschen -> nur wenn noch läuft, sonst gibts nichts mehr zum löschen
ddaten.starterClass.filmLoeschen(url);
if (s.datenDownload.istAbo()) {
// bei Abos Url auch aus dem Logfile löschen, der Film ist damit wieder auf "Anfang"
ddaten.erledigteAbos.urlAusLogfileLoeschen(url);
}
}
arrayDownload.add(download);
}
}
}
if (starten) {
//alle Downloads starten/wiederstarten
DatenDownload.starten(ddaten, arrayDownload);
} else {
//oder alle Downloads stoppen
DatenDownload.statusMelden(arrayDownload, DatenDownload.PROGRESS_NICHT_GESTARTET);
}
}
|
#vulnerable code
private void filmStartenWiederholenStoppen(boolean alle, boolean starten /* starten/wiederstarten oder stoppen */) {
// bezieht sich immer auf "alle" oder nur die markierten
// Film der noch keinen Starts hat wird gestartet
// Film dessen Start schon auf fertig/fehler steht wird wieder gestartet
// bei !starten wird der Film gestoppt
String[] urls;
// ==========================
// erst mal die URLs sammeln
if (alle) {
urls = new String[tabelle.getRowCount()];
for (int i = 0; i < tabelle.getRowCount(); ++i) {
urls[i] = tabelle.getModel().getValueAt(i, DatenDownload.DOWNLOAD_URL_NR).toString();
}
} else {
int[] rows = tabelle.getSelectedRows();
urls = new String[rows.length];
if (rows.length >= 0) {
for (int i = 0; i < rows.length; i++) {
int row = tabelle.convertRowIndexToModel(rows[i]);
urls[i] = tabelle.getModel().getValueAt(row, DatenDownload.DOWNLOAD_URL_NR).toString();
}
} else {
new HinweisKeineAuswahl().zeigen(parentComponent);
}
}
// ========================
// und jetzt abarbeiten
for (String url : urls) {
Start s = ddaten.starterClass.getStart(url);
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(url);
if (starten) {
// --------------
// starten
if (s != null) {
if (s.status > Start.STATUS_RUN) {
// wenn er noch läuft gibts nix
// wenn er schon fertig ist, erst mal fragen vor dem erneuten Starten
int a = JOptionPane.showConfirmDialog(parentComponent, "Film nochmal starten? ==> " + s.datenDownload.arr[DatenDownload.DOWNLOAD_TITEL_NR], "Fertiger Download", JOptionPane.YES_NO_OPTION);
if (a != JOptionPane.YES_OPTION) {
// weiter mit der nächsten URL
continue;
}
ddaten.starterClass.filmLoeschen(url);
if (s.datenDownload.istAbo()) {
// bei Abos Url auch aus dem Logfile löschen, der Film ist damit wieder auf "Anfang"
ddaten.erledigteAbos.urlAusLogfileLoeschen(url);
}
}
}
// jetzt noch starten/wiederstarten
// Start erstellen und zur Liste hinzufügen
download.starten(ddaten);
} else {
// ---------------
// stoppen
if (s != null) {
// wenn kein s -> dann gibts auch nichts zum stoppen oder wieder-starten
if (s.status <= Start.STATUS_RUN) {
// löschen -> nur wenn noch läuft, sonst gibts nichts mehr zum löschen
ddaten.starterClass.filmLoeschen(url);
if (s.datenDownload.istAbo()) {
// bei Abos Url auch aus dem Logfile löschen, der Film ist damit wieder auf "Anfang"
ddaten.erledigteAbos.urlAusLogfileLoeschen(url);
}
}
download.startMelden(DatenDownload.PROGRESS_NICHT_GESTARTET);
}
}
}
}
#location 53
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static synchronized void startMeldungen(String classname) {
versionsMeldungen(classname);
Log.systemMeldung("Programmpfad: " + GuiFunktionenProgramme.getPathJar());
Log.systemMeldung("Verzeichnis Einstellungen: " + Daten.getBasisVerzeichnis());
Log.systemMeldung("Useragent: " + Daten.getUserAgent());
Log.systemMeldung("###########################################################");
Log.systemMeldung("");
Log.systemMeldung("");
}
|
#vulnerable code
public static synchronized void startMeldungen(String classname) {
Log.systemMeldung("###########################################################");
try {
//Version
Log.systemMeldung(Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION);
Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
Log.systemMeldung("Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d));
} catch (IOException ex) {
}
Log.systemMeldung("Klassenname: " + classname);
Log.systemMeldung("");
Log.systemMeldung("Programmpfad: " + GuiFunktionenProgramme.getPathJar());
Log.systemMeldung("Verzeichnis Einstellungen: " + Daten.getBasisVerzeichnis());
Log.systemMeldung("Useragent: " + Daten.getUserAgent());
Log.systemMeldung("");
long totalMem = Runtime.getRuntime().totalMemory();
Log.systemMeldung("totalMemory: " + totalMem / (1024L * 1024L) + " MB");
long maxMem = Runtime.getRuntime().maxMemory();
Log.systemMeldung("maxMemory: " + maxMem / (1024L * 1024L) + " MB");
long freeMem = Runtime.getRuntime().freeMemory();
Log.systemMeldung("freeMemory: " + freeMem / (1024L * 1024L) + " MB");
Log.systemMeldung("###########################################################");
}
#location 6
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getCompileDate() {
// String ret = "";
// try {
// Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
// ret = Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d);
// } catch (Exception ex) {
// Log.fehlerMeldung(569614756, "Log.getCompileDate: ", ex);
// }
// return ret;
final ResourceBundle rb;
String propToken = "BUILDDATE";
String msg = "";
try {
ResourceBundle.clearCache();
rb = ResourceBundle.getBundle("version");
msg = rb.getString(propToken);
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println("Token " + propToken + " not in Propertyfile!");
}
return Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + msg;
}
|
#vulnerable code
public static String getCompileDate() {
String ret = "";
try {
Date d = new Date(Main.class.getResource("Main.class").openConnection().getLastModified());
ret = Konstanten.PROGRAMMNAME + " " + Konstanten.VERSION + " [Buildnummer: " + getBuildNr() + "] - Compiled: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm").format(d);
} catch (Exception ex) {
Log.fehlerMeldung(569614756, "Log.getCompileDate: ", ex);
}
return ret;
}
#location 4
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public synchronized void abosSuchen() {
// in der Filmliste nach passenden Filmen suchen und
// in die Liste der Downloads eintragen
boolean gefunden = false;
DatenFilm film;
DatenAbo abo;
boolean checkBlack = !Boolean.parseBoolean(Daten.system[Konstanten.SYSTEM_BLACKLIST_AUSGESCHALTET_NR])
&& Boolean.parseBoolean(Daten.system[Konstanten.SYSTEM_BLACKLIST_AUCH_ABO_NR]);
ListIterator<DatenFilm> itFilm = Daten.listeFilme.listIterator();
while (itFilm.hasNext()) {
film = itFilm.next();
abo = ddaten.listeAbo.getAboFuerFilm(film);
if (abo == null) {
continue;
} else if (!abo.aboIstEingeschaltet()) {
continue;
} else if (ddaten.erledigteAbos.urlPruefen(film.arr[DatenFilm.FILM_URL_NR])) {
// ist schon im Logfile, weiter
continue;
} else if (checkListe(film.arr[DatenFilm.FILM_URL_NR])) {
// haben wir schon in der Downloadliste
continue;
} else if (checkBlack) {
if (!ddaten.listeBlacklist.checkBlackOkFilme_Downloads(film)) { // wenn Blacklist auch für Abos, dann ers mal da schauen
continue;
}
} else {
//diesen Film in die Downloadliste eintragen
abo.arr[DatenAbo.ABO_DOWN_DATUM_NR] = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
//wenn nicht doppelt, dann in die Liste schreiben
DatenPset pSet = ddaten.listePset.getPsetAbo(abo.arr[DatenAbo.ABO_PSET_NR]);
if (pSet != null) {
if (!abo.arr[DatenAbo.ABO_PSET_NR].equals(pSet.arr[DatenPset.PROGRAMMSET_NAME_NR])) {
abo.arr[DatenAbo.ABO_PSET_NR] = pSet.arr[DatenPset.PROGRAMMSET_NAME_NR];
}
add(new DatenDownload(pSet, film, Start.QUELLE_ABO, abo, "", ""));
gefunden = true;
}
}
} //while
if (gefunden) {
listeNummerieren();
}
}
|
#vulnerable code
public synchronized void abosSuchen() {
// in der Filmliste nach passenden Filmen suchen und
// in die Liste der Downloads eintragen
boolean gefunden = false;
DatenFilm film;
DatenAbo abo;
boolean checkBlack = !Boolean.parseBoolean(Daten.system[Konstanten.SYSTEM_BLACKLIST_AUSGESCHALTET_NR])
&& Boolean.parseBoolean(Daten.system[Konstanten.SYSTEM_BLACKLIST_AUCH_ABO_NR]);
ListIterator<DatenFilm> itFilm = Daten.listeFilme.listIterator();
while (itFilm.hasNext()) {
film = itFilm.next();
abo = ddaten.listeAbo.getAboFuerFilm(film);
if (abo == null) {
continue;
} else if (!abo.aboIstEingeschaltet()) {
continue;
} else if (ddaten.erledigteAbos.urlPruefen(film.arr[DatenFilm.FILM_URL_NR])) {
// ist schon im Logfile, weiter
continue;
} else if (checkListe(film.arr[DatenFilm.FILM_URL_NR])) {
// haben wir schon in der Downloadliste
continue;
} else if (checkBlack && !ddaten.listeBlacklist.checkBlackOkFilme_Downloads(film)) {
// wenn Blacklist auch für Abos, dann ers mal da schauen
continue;
} else {
//diesen Film in die Downloadliste eintragen
abo.arr[DatenAbo.ABO_DOWN_DATUM_NR] = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
//wenn nicht doppelt, dann in die Liste schreiben
DatenPset pSet = ddaten.listePset.getPsetAbo(abo.arr[DatenAbo.ABO_PSET_NR]);
if (!abo.arr[DatenAbo.ABO_PSET_NR].equals(pSet.arr[DatenPset.PROGRAMMSET_NAME_NR])) {
// abo ändern
abo.arr[DatenAbo.ABO_PSET_NR] = pSet.arr[DatenPset.PROGRAMMSET_NAME_NR];
}
if (pSet != null) {
add(new DatenDownload(pSet, film, Start.QUELLE_ABO, abo, "", ""));
gefunden = true;
}
}
} //while
if (gefunden) {
listeNummerieren();
}
}
#location 31
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void speichern() {
try (BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(Files.newOutputStream(historyFilePath)))))
{
for (String h : this)
br.write(h + "\n");
br.flush();
} catch (Exception e) {//Catch exception if any
Log.fehlerMeldung(978786563, Log.FEHLER_ART_PROG, History.class.getName(), e);
}
}
|
#vulnerable code
public void speichern() {
try {
FileOutputStream fstream = new FileOutputStream(datei);
DataOutputStream out = new DataOutputStream(fstream);
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(out));
for (String h : this) {
br.write(h + "\n");
}
br.flush();
out.close();
} catch (Exception e) {//Catch exception if any
Log.fehlerMeldung(978786563, Log.FEHLER_ART_PROG, History.class.getName(), e);
}
}
#location 11
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#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&id=14487&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&id=14485&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, "");
}
}
}
|
#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 17
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void aktFilmSetzen() {
if (this.isShowing()) {
DatenFilm aktFilm = null;
int selectedTableRow = tabelle.getSelectedRow();
if (selectedTableRow >= 0) {
int selectedModelRow = tabelle.convertRowIndexToModel(selectedTableRow);
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenDownload.DOWNLOAD_URL_NR).toString());
if (download != null) {
// wenn beim Löschen aufgerufen, ist der Download schon weg
if (download.film == null) {
// geladener Einmaldownload nach Programmstart
download.film = Daten.listeFilme.getFilmByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenDownload.DOWNLOAD_URL_NR).toString());
} else {
aktFilm = download.film;
}
}
}
filmInfoHud.updateCurrentFilm(aktFilm);
// Beschreibung setzen
panelBeschreibung.setAktFilm(aktFilm);
}
}
|
#vulnerable code
private void aktFilmSetzen() {
if (this.isShowing()) {
DatenFilm aktFilm = null;
int selectedTableRow = tabelle.getSelectedRow();
if (selectedTableRow >= 0) {
int selectedModelRow = tabelle.convertRowIndexToModel(selectedTableRow);
DatenDownload download = ddaten.listeDownloads.getDownloadByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenDownload.DOWNLOAD_URL_NR).toString());
if (download.film == null) {
// geladener Einmaldownload nach Programmstart
download.film = Daten.listeFilme.getFilmByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenDownload.DOWNLOAD_URL_NR).toString());
} else {
aktFilm = download.film;
}
}
filmInfoHud.updateCurrentFilm(aktFilm);
// Beschreibung setzen
panelBeschreibung.setAktFilm(aktFilm);
}
}
#location 8
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public static String getMusterPfadVlc() {
final String PFAD_LINUX_VLC = "/usr/bin/vlc";
final String PFAD_MAC_VLC = "/Applications/VLC.app/Contents/MacOS/VLC";
final String PFAD_WIN_DEFAULT = "C:\\Programme\\VideoLAN\\VLC\\vlc.exe";
final String PFAD_WIN = "\\VideoLAN\\VLC\\vlc.exe";
String pfad;
switch (getOs()) {
case OS_LINUX:
pfad = PFAD_LINUX_VLC;
break;
case OS_MAC:
pfad = PFAD_MAC_VLC;
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;
}
|
#vulnerable code
public static String getMusterPfadVlc() {
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 7
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
private void playerStarten(DatenPset pSet) {
// Url mit Prognr. starten
if (tabelle.getSelectedRow() == -1) {
new HinweisKeineAuswahl().zeigen(parentComponent);
} else if (pSet.istSpeichern()) {
// wenn das pSet zum Speichern (über die Button) gewählt wurde,
// weiter mit dem Dialog "Speichern"
filmSpeichern_(pSet);
} else {
// mit dem flvstreamer immer nur einen Filme starten
int selectedModelRow = tabelle.convertRowIndexToModel(tabelle.getSelectedRow());
DatenFilm datenFilm = DDaten.listeFilmeNachBlackList.getFilmByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenFilm.FILM_URL_NR).toString());
ddaten.starterClass.urlStarten(pSet, datenFilm);
}
}
|
#vulnerable code
private void playerStarten(DatenPset pSet) {
// Url mit Prognr. starten
if (tabelle.getSelectedRow() == -1) {
new HinweisKeineAuswahl().zeigen(parentComponent);
} else if (pSet.istSpeichern()) {
// wenn das pSet zum Speichern (über die Button) gewählt wurde,
// weiter mit dem Dialog "Speichern"
filmSpeichern_(pSet);
} else {
String url = "";
DatenFilm ersterFilm = new DatenFilm();
int selectedTableRows[] = tabelle.getSelectedRows();
for (int l = selectedTableRows.length - 1; l >= 0; --l) {
int selectedModelRow = tabelle.convertRowIndexToModel(selectedTableRows[l]);
ersterFilm = DDaten.listeFilmeNachBlackList.getFilmByUrl(tabelle.getModel().getValueAt(selectedModelRow, DatenFilm.FILM_URL_NR).toString());
// jede neue URL davorsetzen
url = ersterFilm.arr[DatenFilm.FILM_URL_NR] + " " + url;
// und in die History eintragen
//ddaten.history.add(ersterFilm.getUrlOrg()); wird in StartetClass gemacht
}
ersterFilm.arr[DatenFilm.FILM_URL_NR] = url.trim();
ddaten.starterClass.urlStarten(pSet, ersterFilm);
}
}
#location 17
#vulnerability type NULL_DEREFERENCE
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public void laden() {
clear();
if (Files.notExists(historyFilePath))
return;
try (BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(Files.newInputStream(historyFilePath))))) {
String strLine;
while ((strLine = br.readLine()) != null) {
super.add(strLine);
}
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
} catch (Exception e) {
System.err.println("Fehler: " + e);
Log.fehlerMeldung(303049876, Log.FEHLER_ART_PROG, History.class.getName(), e);
}
}
|
#vulnerable code
public void laden() {
clear();
File file = new File(datei);
if (!file.exists()) {
return;
}
try {
FileInputStream fstream = new FileInputStream(datei);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
super.add(strLine);
}
//Close the input stream
in.close();
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
} catch (Exception e) {//Catch exception if any
System.err.println("Fehler: " + e);
Log.fehlerMeldung(303049876, Log.FEHLER_ART_PROG, History.class.getName(), e);
}
}
#location 18
#vulnerability type RESOURCE_LEAK
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#fixed code
public boolean filmlisteIstAelter() {
return filmlisteIstAelter(FilmeLaden.ALTER_FILMLISTE_SEKUNDEN_FUER_AUTOUPDATE);
}
|
#vulnerable code
public boolean filmlisteIstAelter() {
// 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 > FilmeLaden.ALTER_FILMLISTE_SEKUNDEN_FUER_AUTOUPDATE) {
return true;
} else if (ret == -1) {
return true;
}
return false;
}
#location 6
#vulnerability type THREAD_SAFETY_VIOLATION
|
Below is the vulnerable code, please generate the patch based on the following information.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.