]> 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)
committerJeremy Allison <jra@samba.org>
Tue, 17 Dec 2019 22:40:31 +0000 (22:40 +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>
source3/modules/vfs_ceph_snapshots.c

index ce364ae83dc3f8df30385ea9917979ce8073fe83..64f195f4add4ccdbbb5a41e9b0abc4bf56931c3a 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;