From: Waldemar Kozaczuk <
jwkoz...@gmail.com>
Committer: Waldemar Kozaczuk <
jwkoz...@gmail.com>
Branch: master
clock_getres: better validate negative clk_id
Not all negative clock_id numbers are valid. To catch invalid
negative values, apply the formula to calculate the thread id
and try to find matching thread by id.
This fixes broken tst-time.cc
Signed-off-by: Waldemar Kozaczuk <
jwkoz...@gmail.com>
---
diff --git a/libc/time.cc b/libc/time.cc
--- a/libc/time.cc
+++ b/libc/time.cc
@@ -137,6 +137,13 @@ int clock_getres(clockid_t clk_id, struct timespec* ts)
//which represent clock_id for specific thread
if (clk_id >= 0) {
return libc_error(EINVAL);
+ } else {
+ //Reverse the formula used in pthread_getcpuclockid()
+ //and calculate thread id given clk_id
+ pid_t tid = (-clk_id - 2) / 8;
+ if( !sched::thread::find_by_id(tid)) {
+ return libc_error(EINVAL);
+ }
}
}