From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@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 <jwkozac...@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);
+            }
         }
     }
 

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000042db0e060ccf0f9d%40google.com.

Reply via email to