This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new f2d8f86  libc/unistd: Fix getpriority not handling invalid input value
f2d8f86 is described below

commit f2d8f86fb9afbe26ad3ad834fa3c645740ccbcc4
Author: Gustavo Henrique Nihei <gustavo.ni...@espressif.com>
AuthorDate: Thu Mar 11 17:58:13 2021 -0300

    libc/unistd: Fix getpriority not handling invalid input value
---
 libs/libc/unistd/lib_getpriority.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libs/libc/unistd/lib_getpriority.c 
b/libs/libc/unistd/lib_getpriority.c
index 03747a4..0029743 100644
--- a/libs/libc/unistd/lib_getpriority.c
+++ b/libs/libc/unistd/lib_getpriority.c
@@ -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();

Reply via email to