Tested with a bunch of manual sysctl -w's.

OK?

>From 24ae202fd5d39c3c40c029fb878aa15eee33b709 Mon Sep 17 00:00:00 2001
From: Greg Steuck <[email protected]>
Date: Mon, 30 Nov 2020 19:42:19 -0800
Subject: [PATCH] Convert ddb_sysctl to sysctl_bounded_arr

---
 sys/ddb/db_usrreq.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git sys/ddb/db_usrreq.c sys/ddb/db_usrreq.c
index 546822459ca..259e7b56a8f 100644
--- sys/ddb/db_usrreq.c
+++ sys/ddb/db_usrreq.c
@@ -36,6 +36,14 @@
 int    db_log = 1;
 int    db_profile;                     /* Allow dynamic profiling */
 
+const struct sysctl_bounded_args ddb_vars[] = {
+       { DBCTL_RADIX, &db_radix, 8, 16 },
+       { DBCTL_MAXWIDTH, &db_max_width, 0, INT_MAX },
+       { DBCTL_TABSTOP, &db_tab_stop_width, 1, 16 },
+       { DBCTL_MAXLINE, &db_max_line, 0, INT_MAX },
+       { DBCTL_LOG, &db_log, 0, 1 },
+};
+
 int
 ddb_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
     size_t newlen, struct proc *p)
@@ -47,15 +55,6 @@ ddb_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
                return (ENOTDIR);
 
        switch (name[0]) {
-
-       case DBCTL_RADIX:
-               return sysctl_int(oldp, oldlenp, newp, newlen, &db_radix);
-       case DBCTL_MAXWIDTH:
-               return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_width);
-       case DBCTL_TABSTOP:
-               return sysctl_int(oldp, oldlenp, newp, newlen, 
&db_tab_stop_width);
-       case DBCTL_MAXLINE:
-               return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_line);
        case DBCTL_PANIC:
                if (securelevel > 0)
                        return (sysctl_int_lower(oldp, oldlenp, newp, newlen,
@@ -86,8 +85,6 @@ ddb_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
                        return (0);
                }
                break;
-       case DBCTL_LOG:
-               return (sysctl_int(oldp, oldlenp, newp, newlen, &db_log));
        case DBCTL_TRIGGER:
                if (newp && db_console) {
                        struct process *pr = curproc->p_p;
@@ -119,7 +116,8 @@ ddb_sysctl(int *name, u_int namelen, void *oldp, size_t 
*oldlenp, void *newp,
                break;
 #endif /* DDBPROF */
        default:
-               return (EOPNOTSUPP);
+               return (sysctl_bounded_arr(ddb_vars, nitems(ddb_vars), name,
+                   namelen, oldp, oldlenp, newp, newlen));
        }
        /* NOTREACHED */
 }
-- 
2.29.2

Reply via email to