[COMMIT osv master] clock_getres: better validate negative clk_id

1 view
Skip to first unread message

Commit Bot

unread,
Dec 18, 2023, 4:01:55 PM12/18/23
to osv...@googlegroups.com, Waldemar Kozaczuk
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);
+ }
}
}

Reply all
Reply to author
Forward
0 new messages