Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/netbsd32 clamp getrlimit the same way we clamp se...



details:   https://anonhg.NetBSD.org/src/rev/074c9aad1d98
branches:  trunk
changeset: 345226:074c9aad1d98
user:      christos <christos%NetBSD.org@localhost>
date:      Fri May 13 16:54:36 2016 +0000

description:
clamp getrlimit the same way we clamp setrlimit

diffstat:

 sys/compat/netbsd32/netbsd32_netbsd.c |  66 +++++++++++++++++++++-------------
 1 files changed, 41 insertions(+), 25 deletions(-)

diffs (110 lines):

diff -r 2a213999d37e -r 074c9aad1d98 sys/compat/netbsd32/netbsd32_netbsd.c
--- a/sys/compat/netbsd32/netbsd32_netbsd.c     Fri May 13 15:55:59 2016 +0000
+++ b/sys/compat/netbsd32/netbsd32_netbsd.c     Fri May 13 16:54:36 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_netbsd.c,v 1.199 2016/02/28 23:24:35 khorben Exp $    */
+/*     $NetBSD: netbsd32_netbsd.c,v 1.200 2016/05/13 16:54:36 christos Exp $   */
 
 /*
  * Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.199 2016/02/28 23:24:35 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.200 2016/05/13 16:54:36 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -1448,23 +1448,51 @@
        return sys_fpathconf(l, &ua, retval);
 }
 
+static void
+fixlimit(int which, struct rlimit *alim)
+{
+       switch (which) {
+       case RLIMIT_DATA:
+               if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
+                       alim->rlim_cur = MAXDSIZ32;
+               if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
+                       alim->rlim_max = MAXDSIZ32;
+               return; 
+       case RLIMIT_STACK:
+               if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
+                       alim->rlim_cur = MAXSSIZ32;
+               if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
+                       alim->rlim_max = MAXSSIZ32;
+               return;
+       default:
+               return;
+       }
+}
+
 int
-netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap, register_t *retval)
+netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
+    register_t *retval)
 {
        /* {
                syscallarg(int) which;
                syscallarg(netbsd32_rlimitp_t) rlp;
        } */
        int which = SCARG(uap, which);
+       struct rlimit alim;
 
        if ((u_int)which >= RLIM_NLIMITS)
-               return (EINVAL);
-       return (copyout(&l->l_proc->p_rlimit[which],
-           SCARG_P32(uap, rlp), sizeof(struct rlimit)));
+               return EINVAL;
+
+       alim = l->l_proc->p_rlimit[which];
+
+       fixlimit(which, &alim);
+
+       return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
 }
 
 int
-netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap, register_t *retval)
+netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
+    register_t *retval)
 {
        /* {
                syscallarg(int) which;
@@ -1474,28 +1502,16 @@
        struct rlimit alim;
        int error;
 
+       if ((u_int)which >= RLIM_NLIMITS)
+               return EINVAL;
+
        error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
        if (error)
                return (error);
 
-       switch (which) {
-       case RLIMIT_DATA:
-               if (LIMITCHECK(alim.rlim_cur, MAXDSIZ32))
-                       alim.rlim_cur = MAXDSIZ32;
-               if (LIMITCHECK(alim.rlim_max, MAXDSIZ32))
-                       alim.rlim_max = MAXDSIZ32;
-               break;
-
-       case RLIMIT_STACK:
-               if (LIMITCHECK(alim.rlim_cur, MAXSSIZ32))
-                       alim.rlim_cur = MAXSSIZ32;
-               if (LIMITCHECK(alim.rlim_max, MAXSSIZ32))
-                       alim.rlim_max = MAXSSIZ32;
-       default:
-               break;
-       }
-
-       return (dosetrlimit(l, l->l_proc, which, &alim));
+       fixlimit(which, &alim);
+
+       return dosetrlimit(l, l->l_proc, which, &alim);
 }
 
 int



Home | Main Index | Thread Index | Old Index