From 1517c7669358a56da9a02e1635b15c93acfea59a Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 12 Dec 2019 22:14:50 +0100 Subject: [PATCH] vfs_ceph_snapshots: fix root relative path handling 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 --- source3/modules/vfs_ceph_snapshots.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source3/modules/vfs_ceph_snapshots.c b/source3/modules/vfs_ceph_snapshots.c index 52439da2604..95a0c8d010d 100644 --- a/source3/modules/vfs_ceph_snapshots.c +++ b/source3/modules/vfs_ceph_snapshots.c @@ -401,8 +401,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; @@ -545,7 +549,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; -- 2.16.4