The Arg union is generally passed to functions called from a Key or
Button. One of its members, "v", allows passing a `const void *` with
the receiving function determining the intent and casting as
appropriate.

There are a few places in the dwm code where we cast away the constness
of this pointer unnecessarily, potentially allowing its mutation. For
example, execvp's argv is a `char *const *`, but we just cast away the
outer const pointer.

The other case is in setlayout(), but that case is trivial: there's no
issue just casting the const void pointer to a `const Layout *`.
---
 dwm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/dwm.c b/dwm.c
index 253aba7..4c0f679 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1504,7 +1504,7 @@ setlayout(const Arg *arg)
        if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
                selmon->sellt ^= 1;
        if (arg && arg->v)
-               selmon->lt[selmon->sellt] = (Layout *)arg->v;
+               selmon->lt[selmon->sellt] = (const Layout *)arg->v;
        strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof 
selmon->ltsymbol);
        if (selmon->sel)
                arrange(selmon);
@@ -1642,11 +1642,12 @@ spawn(const Arg *arg)
        if (arg->v == dmenucmd)
                dmenumon[0] = '0' + selmon->num;
        if (fork() == 0) {
+               char *const *cmd = arg->v;
                if (dpy)
                        close(ConnectionNumber(dpy));
                setsid();
-               execvp(((char **)arg->v)[0], (char **)arg->v);
-               die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
+               execvp(cmd[0], cmd);
+               die("dwm: execvp '%s' failed:", cmd[0]);
        }
 }
 
-- 
2.37.2


Reply via email to