diff options
author | 2012-02-19 02:07:48 +0000 | |
---|---|---|
committer | 2012-02-19 02:07:48 +0000 | |
commit | e97833818df19cf10e167ed6cd3f01e4d076a286 (patch) | |
tree | 70d71cf5856daba6393f9db44590d63d0bcf82e0 | |
parent | Fix previous commit: _rthread_init() was static. (diff) | |
download | wireguard-openbsd-e97833818df19cf10e167ed6cd3f01e4d076a286.tar.xz wireguard-openbsd-e97833818df19cf10e167ed6cd3f01e4d076a286.zip |
Validate in pthread_attr_set{scope,sched{param,policy},inheritsched}()
the requested new value
-rw-r--r-- | lib/librthread/rthread_attr.c | 6 | ||||
-rw-r--r-- | lib/librthread/rthread_sched.c | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c index 900651e59b3..ef0c30efbf1 100644 --- a/lib/librthread/rthread_attr.c +++ b/lib/librthread/rthread_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_attr.c,v 1.14 2012/02/18 22:03:21 guenther Exp $ */ +/* $OpenBSD: rthread_attr.c,v 1.15 2012/02/19 02:07:48 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -191,7 +191,9 @@ pthread_attr_getscope(const pthread_attr_t *attrp, int *contentionscope) int pthread_attr_setscope(pthread_attr_t *attrp, int contentionscope) { - /* XXX contentionscope should be validated here */ + if (contentionscope != PTHREAD_SCOPE_SYSTEM || + contentionscope != PTHREAD_SCOPE_PROCESS) + return (EINVAL); (*attrp)->contention_scope = contentionscope; return (0); diff --git a/lib/librthread/rthread_sched.c b/lib/librthread/rthread_sched.c index 25e4b4c804e..07cfdfe9e20 100644 --- a/lib/librthread/rthread_sched.c +++ b/lib/librthread/rthread_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sched.c,v 1.9 2011/12/28 04:59:31 guenther Exp $ */ +/* $OpenBSD: rthread_sched.c,v 1.10 2012/02/19 02:07:48 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -43,6 +43,10 @@ int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param) { + /* XXX return ENOTSUP for SCHED_{FIFO,RR}? */ + if (policy != SCHED_OTHER && policy != SCHED_FIFO && + policy != SCHED_RR) + return (EINVAL); thread->sched_policy = policy; if (param) thread->sched_param = *param; @@ -77,6 +81,10 @@ pthread_attr_getschedpolicy(const pthread_attr_t *attrp, int *policy) int pthread_attr_setschedpolicy(pthread_attr_t *attrp, int policy) { + /* XXX return ENOTSUP for SCHED_{FIFO,RR}? */ + if (policy != SCHED_OTHER && policy != SCHED_FIFO && + policy != SCHED_RR) + return (EINVAL); (*attrp)->sched_policy = policy; return (0); @@ -93,6 +101,9 @@ pthread_attr_getinheritsched(const pthread_attr_t *attrp, int *inherit) int pthread_attr_setinheritsched(pthread_attr_t *attrp, int inherit) { + if (inherit != PTHREAD_INHERIT_SCHED && + inherit != PTHREAD_EXPLICIT_SCHED) + return (EINVAL); (*attrp)->sched_inherit = inherit; return (0); |