This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nptl/10090] New: Add the invalid sched_priority checking for pthread_attr_setschedparam


I tested the scheduler of NPTL thread, and found that when I set an invalid 
sched_priority by pthread_attr_setschedparam(), the function returns 0. Then 
pthread_create() will fail.

     pthread_attr_setschedparam()           <- return 0
     -> pthread_create()                 <- return failed

In pthread_attr_setschedparam() manual, it should return EINVAL when 
sched_priority 
is invalid.

A test program which reproduces the problem on current glibc is attached. This 
program sets a invalid sched_priority by pthread_attr_setschedparam(), sets 
PTHREAD_EXPLICIT_SCHED by pthread_attr_setinheritsched() and then calls 
pthread_create().

Although pthread_create() has checked the invalid sched_priority, 
pthread_attr_setschedparam()
should check too. The users should found the error as soon as possible.

Signed-off-by: Zhang Xiliang <zhangxiliang@cn.fujitsu.com>
---
 nptl/pthread_attr_setschedparam.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/nptl/pthread_attr_setschedparam.c 
b/nptl/pthread_attr_setschedparam.c
index 976ad13..6db488c 100644
--- a/nptl/pthread_attr_setschedparam.c
+++ b/nptl/pthread_attr_setschedparam.c
@@ -31,6 +31,10 @@ __pthread_attr_setschedparam (attr, param)
   assert (sizeof (*attr) >= sizeof (struct pthread_attr));
   struct pthread_attr *iattr = (struct pthread_attr *) attr;
 
+  if (param->sched_priority > sched_get_priority_max(iattr->schedpolicy)
+ || param->sched_priority < sched_get_priority_min(iattr->schedpolicy))
+    return EINVAL;
+
   /* Copy the new values.  */
   memcpy (&iattr->schedparam, param, sizeof (struct sched_param));

-- 
           Summary: Add the invalid sched_priority checking for
                    pthread_attr_setschedparam
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: zhangxiliang at cn dot fujitsu dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=10090

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]