From: Sage Weil Date: Tue, 21 May 2013 19:15:49 +0000 (-0700) Subject: rbd: prevent import of a dir X-Git-Tag: v0.64~84 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cbff720ff54ac6948f455cf82c4c2eee31d703f4;p=ceph.git rbd: prevent import of a dir Fixes: #2865 Signed-off-by: Sage Weil --- diff --git a/qa/workunits/rbd/import_export.sh b/qa/workunits/rbd/import_export.sh index bbbdbe629998..353a47fffbe3 100755 --- a/qa/workunits/rbd/import_export.sh +++ b/qa/workunits/rbd/import_export.sh @@ -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 diff --git a/src/rbd.cc b/src/rbd.cc index 5e7389162f2f..17ccd061dc1c 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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;