libc/unistd: Fix getpriority not handling invalid input value

This commit is contained in:
Gustavo Henrique Nihei 2021-03-11 17:58:13 -03:00 committed by Xiang Xiao
parent cf8521e6de
commit f2d8f86fb9

View File

@ -23,6 +23,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <sys/resource.h>
#include <sched.h>
#include <errno.h>
@ -46,7 +47,13 @@
* Returned Value:
* Upon successful completion, getpriority() shall return an integer in
* the range -{NZERO} to {NZERO}-1. Otherwise, -1 shall be returned and
* errno set to indicate the error.
* errno set to indicate the error. The following errors may be
* reported:
*
* - ESRCH: No process was located using the which and who values
* specified.
* - EINVAL: which was not one of PRIO_PROCESS, PRIO_PGRP, or
* PRIO_USER.
*
* Assumptions:
*
@ -57,6 +64,12 @@ int getpriority(int which, id_t who)
struct sched_param param;
int ret;
if (which > PRIO_USER || which < PRIO_PROCESS)
{
set_errno(EINVAL);
return ERROR;
}
if (who == 0)
{
who = getpid();