summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_resource.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-09-25 20:24:32 +0000
committercheloha <cheloha@openbsd.org>2020-09-25 20:24:32 +0000
commitd52ff6db0e21473ed5e2ebd1e1fa1453ae7080cc (patch)
treedfcc2a294cfb534dd02d3dab3b76b69356de1e37 /sys/kern/kern_resource.c
parentmove test-tls13-finished.py from slow tests to normal tests. (diff)
downloadwireguard-openbsd-d52ff6db0e21473ed5e2ebd1e1fa1453ae7080cc.tar.xz
wireguard-openbsd-d52ff6db0e21473ed5e2ebd1e1fa1453ae7080cc.zip
setpriority(2): don't treat booleans as scalars
The variable "found" in sys_setpriority() is used as a boolean. We should set it to 1 to indicate that we found the object we were looking for instead of incrementing it. deraadt@ notes that the current code is not buggy, because OpenBSD cannot support anywhere near 2^32 processes, but agrees that incrementing the variable signals the wrong thing to the reader. ok millert@ deraadt@
Diffstat (limited to 'sys/kern/kern_resource.c')
-rw-r--r--sys/kern/kern_resource.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 341315d03e0..0111bfa733a 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_resource.c,v 1.68 2019/07/15 20:44:48 mpi Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.69 2020/09/25 20:24:32 cheloha Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
@@ -157,7 +157,7 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
if (pr == NULL)
break;
error = donice(curp, pr, SCARG(uap, prio));
- found++;
+ found = 1;
break;
case PRIO_PGRP: {
@@ -169,7 +169,7 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
break;
LIST_FOREACH(pr, &pg->pg_members, ps_pglist) {
error = donice(curp, pr, SCARG(uap, prio));
- found++;
+ found = 1;
}
break;
}
@@ -180,14 +180,14 @@ sys_setpriority(struct proc *curp, void *v, register_t *retval)
LIST_FOREACH(pr, &allprocess, ps_list)
if (pr->ps_ucred->cr_uid == SCARG(uap, who)) {
error = donice(curp, pr, SCARG(uap, prio));
- found++;
+ found = 1;
}
break;
default:
return (EINVAL);
}
- if (found == 0)
+ if (!found)
return (ESRCH);
return (error);
}