1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-16 15:39:36 +00:00

Fix a possible crash in thread_is_available()

When we have more then 2 threads then we do an array
access with index 'Threads[slave].activeSplitPoints - 1'
This should be >= 0 because we tested the variable just
few statements before, but because is a shared variable
it could be that the 'slave' thread set the value to zero
just after we test it, so that when we use the decremented
variable for array access we crash.

Bug spotted by Bruno Causse.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-01-25 22:18:12 +01:00
parent 647b79b556
commit de17652e47
2 changed files with 13 additions and 8 deletions

View file

@ -2847,17 +2847,22 @@ namespace {
if(!Threads[slave].idle || slave == master)
return false;
if(Threads[slave].activeSplitPoints == 0)
// No active split points means that the thread is available as a slave
// for any other thread.
return true;
// Make a local copy to be sure doesn't change under our feet
int localActiveSplitPoints = Threads[slave].activeSplitPoints;
if (localActiveSplitPoints == 0)
// No active split points means that the thread is available as
// a slave for any other thread.
return true;
if(ActiveThreads == 2)
return true;
// Apply the "helpful master" concept if possible.
if(SplitPointStack[slave][Threads[slave].activeSplitPoints-1].slaves[master])
return true;
// Apply the "helpful master" concept if possible. Use localActiveSplitPoints
// that is known to be > 0, instead of Threads[slave].activeSplitPoints that
// could have been set to 0 by another thread leading to an out of bound access.
if (SplitPointStack[slave][localActiveSplitPoints - 1].slaves[master])
return true;
return false;
}

View file

@ -64,7 +64,7 @@ struct SplitPoint {
struct Thread {
SplitPoint *splitPoint;
int activeSplitPoints;
volatile int activeSplitPoints;
uint64_t nodes;
uint64_t betaCutOffs[2];
bool failHighPly1;