From: wuxiangwei Date: Wed, 16 Dec 2015 03:47:49 +0000 (-0500) Subject: rbd:add destination image name validation for rbd-fuse mv operation X-Git-Tag: v10.0.3~191^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d13f6024d3763293301ab4d5f0e9f2acdbb5fc15;p=ceph.git rbd:add destination image name validation for rbd-fuse mv operation add validation for destination image name to avoid image name contains invalid characters, such as "/" and "@". Signed-off-by: Xiangwei Wu wuxiangwei@h3c.com --- diff --git a/src/rbd_fuse/rbd-fuse.cc b/src/rbd_fuse/rbd-fuse.cc index 838c2fea9cd..12bcf973f68 100644 --- a/src/rbd_fuse/rbd-fuse.cc +++ b/src/rbd_fuse/rbd-fuse.cc @@ -18,6 +18,7 @@ #include #include #include +#include #if defined(__FreeBSD__) #include @@ -537,11 +538,26 @@ rbdfs_create(const char *path, mode_t mode, struct fuse_file_info *fi) int rbdfs_rename(const char *path, const char *destname) { const char *srcname = NULL; + const char *extra[] = {" ", "@", "/"}; + std::string image_dest_name(destname + 1); + + // check image dest name + if (image_dest_name.empty()) + return -EINVAL; + + unsigned int sz = sizeof(extra) / sizeof(const char*); + for (unsigned int i = 0; i < sz; i++) + { + std::string ex(extra[i]); + if (std::string::npos != image_dest_name.find(ex)) + return -EINVAL; + } + if (strcmp(path, "/") == 0) return -EINVAL; srcname = path + 1; - return rbd_rename(ioctx, srcname, destname + 1); + return rbd_rename(ioctx, srcname, image_dest_name.c_str()); } int