]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd:add destination image name validation for rbd-fuse mv operation
authorwuxiangwei <wuxiangwei@h3c.com>
Wed, 16 Dec 2015 03:47:49 +0000 (22:47 -0500)
committerwuxiangwei <wuxiangwei@h3c.com>
Wed, 16 Dec 2015 03:47:57 +0000 (22:47 -0500)
add validation for destination image name to
avoid image name contains invalid characters, such as "/" and "@".

Signed-off-by: Xiangwei Wu wuxiangwei@h3c.com
src/rbd_fuse/rbd-fuse.cc

index 838c2fea9cd681e020c74e6d9f730d2e2a433286..12bcf973f68abe28ecae1d865e5222b2269e721a 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <assert.h>
+#include <string>
 
 #if defined(__FreeBSD__)
 #include <sys/param.h>
@@ -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