xinu-os / xinu

Repository for Xinu source code
http://xinu-os.org/
Other
430 stars 128 forks source link

Check for validity of tid before accessing thrtab, existing code can lead to exception ( solved as part of cs503 homework at purdue university) #1

Closed eerpini closed 13 years ago

eerpini commented 13 years ago

Should check for the validity of the tid before accessing the thread table ...

mjschultz commented 13 years ago

I'm not seeing the problem, actually. Assuming tid is invalid and thrptr will then point to a bad location, it is never dereferenced before the isbadtid() check (i.e. an exception won't occur). This thrptr is set way late because we've already run thrptr->state != THRSUSP which will be invalid.

In reality the two checks should be exploded with a isbadtid(tid) check, set thrptr, then check thrptr->state. In practice that gives no benefit (and makes more verbose code).

eerpini commented 13 years ago

Agree, thinking about it, the code is not really going to affect much, but looked faulty on a first glance.

Yes, a isbadtid(tid) followed by a thrtab access and then a state check would be the right way to do it, I do not see any possible way that tid would land up with a value outlier enough to cause an exception, but checking if the tid is valid first is a good idea.