On Mon, 30 Nov 2020 20:04:10 -0800
Greg Steuck <[email protected]> wrote:
> Tested with a bunch of manual sysctl -w's.
>
> OK?
I'm not sure about this diff. I'm more likely to do
ddb{0}> set $radix = 0t2
and less likely to do
# sysctl ddb.radix=2
but you enforce the range check (radix in 8..16) only in sysctl,
not in ddb set.
If I do ddb set a bad value, then sysctl refuses to show the value:
# sysctl ddb.console=1
ddb.console: 0 -> 1
# sysctl ddb.trigger=1
Stopped at ddb_sysctl+0x114: ori r0,r0,0x0
ddb{0}> set $radix = 0t2
ddb{0}> c
ddb.trigger: 0 -> 1
# sysctl ddb.radix
sysctl: ddb.radix: Invalid argument
This diff might be better than doing nothing? I'm not sure. --George
> 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
>
--
George Koehler <[email protected]>