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

The file is built by vmd and vmctl.

I'm uncertain if we want a truncation check here.  Both in vmd and
vmctl, the path has been validated by a previous open(), but given
the code complexity, do we want to rely on this?


Index: usr.sbin/vmd/vioqcow2.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.13
diff -u -p -r1.13 vioqcow2.c
--- usr.sbin/vmd/vioqcow2.c     10 Jan 2019 19:21:02 -0000      1.13
+++ usr.sbin/vmd/vioqcow2.c     14 Oct 2020 20:57:31 -0000
@@ -145,6 +145,7 @@ virtio_qcow2_init(struct virtio_backing 
 ssize_t
 virtio_qcow2_get_base(int fd, char *path, size_t npath, const char *dpath)
 {
+       char dpathbuf[PATH_MAX];
        char expanded[PATH_MAX];
        struct qcheader header;
        uint64_t backingoff;
@@ -186,7 +187,8 @@ virtio_qcow2_get_base(int fd, char *path
                        return -1;
                }
        } else {
-               s = dirname(dpath);
+               strlcpy(dpathbuf, dpath, sizeof(dpathbuf));
+               s = dirname(dpathbuf);
                if (snprintf(expanded, sizeof(expanded),
                    "%s/%s", s, path) >= (int)sizeof(expanded)) {
                        log_warnx("path too long: %s/%s", s, path);
-- 
Christian "naddy" Weisgerber                          [email protected]

Reply via email to