]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_snapshots: fix root relative path handling
authorDavid Disseldorp <ddiss@samba.org>
Thu, 12 Dec 2019 21:14:50 +0000 (22:14 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 14 Jan 2020 08:30:24 +0000 (08:30 +0000)
For file paths relative to root, ceph_snap_get_parent_path() may return
an empty parent dir string, in which case the CephFS snashot path should
be ".snap".

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14216

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 54293f92cd83efc3a5a78fc29a85643921da9d32)

source3/modules/vfs_ceph_snapshots.c

index 4d935a55a1a36ece378854297cbcdaf688f3ae09..0b5f7ab59a5181019dc8c01a29e28e210f4af5ad 100644 (file)
@@ -390,8 +390,12 @@ static int ceph_snap_get_shadow_copy_data(struct vfs_handle_struct *handle,
                parent_dir = tmp;
        }
 
-       ret = snprintf(snaps_path, sizeof(snaps_path), "%s/%s",
-                      parent_dir, snapdir);
+       if (strlen(parent_dir) == 0) {
+               ret = strlcpy(snaps_path, snapdir, sizeof(snaps_path));
+       } else {
+               ret = snprintf(snaps_path, sizeof(snaps_path), "%s/%s",
+                              parent_dir, snapdir);
+       }
        if (ret >= sizeof(snaps_path)) {
                ret = -EINVAL;
                goto err_out;
@@ -534,7 +538,11 @@ static int ceph_snap_gmt_convert_dir(struct vfs_handle_struct *handle,
        /*
         * Temporally use the caller's return buffer for this.
         */
-       ret = snprintf(_converted_buf, buflen, "%s/%s", name, snapdir);
+       if (strlen(name) == 0) {
+               ret = strlcpy(_converted_buf, snapdir, buflen);
+       } else {
+               ret = snprintf(_converted_buf, buflen, "%s/%s", name, snapdir);
+       }
        if (ret >= buflen) {
                ret = -EINVAL;
                goto err_out;