Accommodate a basename(3) that takes a non-const parameter and may
in fact modify the string buffer.

The length of anchor has already been checked in main().

ok?

Index: sbin/pfctl/pfctl.c
===================================================================
RCS file: /cvs/src/sbin/pfctl/pfctl.c,v
retrieving revision 1.382
diff -u -p -r1.382 pfctl.c
--- sbin/pfctl/pfctl.c  16 Jan 2020 01:02:20 -0000      1.382
+++ sbin/pfctl/pfctl.c  13 Oct 2020 20:45:16 -0000
@@ -2241,16 +2241,19 @@ pfctl_get_anchors(int dev, const char *a
 {
        struct pfioc_ruleset    pr;
        static struct pfr_anchors anchors;
+       char anchorbuf[PATH_MAX];
        char *n;
 
        SLIST_INIT(&anchors);
 
        memset(&pr, 0, sizeof(pr));
        if (*anchor != '\0') {
-               n = dirname(anchor);
+               strlcpy(anchorbuf, anchor, sizeof(anchorbuf));
+               n = dirname(anchorbuf);
                if (n[0] != '.' && n[1] != '\0')
                        strlcpy(pr.path, n, sizeof(pr.path));
-               n = basename(anchor);
+               strlcpy(anchorbuf, anchor, sizeof(anchorbuf));
+               n = basename(anchorbuf);
                if (n != NULL)
                        strlcpy(pr.name, n, sizeof(pr.name));
        }
-- 
Christian "naddy" Weisgerber                          [email protected]

Reply via email to