]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: prevent import of a dir
authorSage Weil <sage@inktank.com>
Tue, 21 May 2013 19:15:49 +0000 (12:15 -0700)
committerSage Weil <sage@inktank.com>
Tue, 21 May 2013 19:16:24 +0000 (12:16 -0700)
Fixes: #2865
Signed-off-by: Sage Weil <sage@inktank.com>
qa/workunits/rbd/import_export.sh
src/rbd.cc

index bbbdbe62999848fb234bd19da562e842ebfcaa58..353a47fffbe3b7179999d58886d4dcbc18a2e321 100755 (executable)
@@ -22,6 +22,11 @@ compare_files_and_ondisk_sizes () {
     [ $origsize = $exportsize ]
 }
 
+# cannot import a dir
+mkdir foo.$$
+rbd import foo.$$ foo.dir && exit 1 || true   # should fail
+rmdir foo.$$
+
 # create a sparse file
 dd if=/bin/sh of=/tmp/img bs=1k count=1 seek=10
 dd if=/bin/dd of=/tmp/img bs=1k count=10 seek=100
index 5e7389162f2f2d4ce103bbc89874ce3c6566bb52..17ccd061dc1cdd27f2e0aff32c73a6ce5008abd7 100644 (file)
@@ -1310,6 +1310,11 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
       cerr << "rbd: stat error " << path << std::endl;
       goto done;
     }
+    if (S_ISDIR(stat_buf.st_mode)) {
+      r = -EISDIR;
+      cerr << "rbd: cannot import a directory" << std::endl;
+      goto done;
+    }
     if (stat_buf.st_size)
       size = (uint64_t)stat_buf.st_size;