diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | src/bindfs.c | 11 | ||||
-rw-r--r-- | tests/common.rb | 16 | ||||
-rwxr-xr-x | tests/test_bindfs.rb | 31 |
4 files changed, 60 insertions, 7 deletions
@@ -1,3 +1,12 @@ +2017-01-29 Martin Pärtel <martin dot partel at gmail dot com> + + * Fixed option parsing failure when source dir has a comma (issue #47). + +2016-10-30 Martin Pärtel <martin dot partel at gmail dot com> + + * Removed ./configure --enable-debug, which has done nothing for some + time. + 2016-10-29 Martin Pärtel <martin dot partel at gmail dot com> * Fixed compilation of tests on some non-x86 platforms. diff --git a/src/bindfs.c b/src/bindfs.c index 6ba9e68..c87b3d8 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -2155,8 +2155,15 @@ int main(int argc, char *argv[]) fuse_opt_add_arg(&args, "-ouse_ino"); fuse_opt_add_arg(&args, "-oreaddir_ino"); - /* Show the source dir in the first field on /etc/mtab. */ - { + /* Show the source dir in the first field on /etc/mtab, to be consistent + with "real" filesystems. + + We don't do this if the source dir contains some special characters. + Comma is on this list because it would mess up FUSE's option parsing + (issue #47). The character blacklist is likely not complete, which is + acceptable since this is not a security check. The aim is to avoid giving + the user a confusing error. */ + if (strpbrk(settings.mntsrc, ", \t\n") == NULL) { char *tmp = sprintf_new("-ofsname=%s", settings.mntsrc); fuse_opt_add_arg(&args, tmp); free(tmp); diff --git a/tests/common.rb b/tests/common.rb index 518aab2..81d45fc 100644 --- a/tests/common.rb +++ b/tests/common.rb @@ -19,6 +19,7 @@ # require 'fileutils' +require 'shellwords' include FileUtils # Set the default umask for all tests @@ -92,7 +93,9 @@ def testenv(bindfs_args, options = {}, &block) options = { :title => bindfs_args, :valgrind => valgrind_options != nil, - :valgrind_opts => valgrind_options + :valgrind_opts => valgrind_options, + :srcdir_name => 'src', + :mntdir_name => 'mnt' }.merge(options) # todo: less repetitive and more careful error handling and cleanup @@ -100,6 +103,9 @@ def testenv(bindfs_args, options = {}, &block) puts "--- #{options[:title]} ---" puts "[ #{bindfs_args} ]" + srcdir = options[:srcdir_name] + mntdir = options[:mntdir_name] + begin Dir.mkdir TESTDIR_NAME rescue Exception => ex @@ -108,15 +114,15 @@ def testenv(bindfs_args, options = {}, &block) begin Dir.chdir TESTDIR_NAME - Dir.mkdir 'src' - Dir.mkdir 'mnt' + Dir.mkdir srcdir + Dir.mkdir mntdir rescue Exception => ex fail!("ERROR preparing testdir at #{TESTDIR_NAME}", ex) end bindfs_pid = nil begin - cmd = "../#{EXECUTABLE_PATH} #{bindfs_args} -f src mnt" + cmd = "../#{EXECUTABLE_PATH} #{bindfs_args} -f #{Shellwords.escape(srcdir)} #{Shellwords.escape(mntdir)}" if options[:valgrind] cmd = "valgrind --error-exitcode=100 #{options[:valgrind_opts]} #{cmd}" end @@ -146,7 +152,7 @@ def testenv(bindfs_args, options = {}, &block) end begin - unless system(umount_cmd + ' mnt') + unless system(umount_cmd + ' ' + Shellwords.escape(mntdir)) raise Exception.new(umount_cmd + " failed with status #{$?}") end Process.wait bindfs_pid diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb index 39f709e..96d6660 100755 --- a/tests/test_bindfs.rb +++ b/tests/test_bindfs.rb @@ -695,6 +695,37 @@ testenv("", :title => "reading directory with rewind") do end end +# Issue 47 +testenv("", :title => "srcdir with comma", :srcdir_name => "a,b") do + touch('a,b/f') + assert { File.exist?('mnt/f') } +end + +testenv("", :title => "mntdir with comma", :mntdir_name => "a,b") do + touch('src/f') + assert { File.exist?('a,b/f') } +end + +testenv("", :title => "srcdir with space", :srcdir_name => "a b") do + touch('a b/f') + assert { File.exist?('mnt/f') } +end + +testenv("", :title => "mntdir with space", :mntdir_name => "a b") do + touch('src/f') + assert { File.exist?('a b/f') } +end + +testenv("", :title => "srcdir with newline", :srcdir_name => "a\nb") do + touch("a\nb/f") + assert { File.exist?('mnt/f') } +end + +testenv("", :title => "mntdir with newline", :mntdir_name => "a\nb") do + touch('src/f') + assert { File.exist?("a\nb/f") } +end + # FIXME: this stuff around testenv is a hax, and testenv may also exit(), which defeats the 'ensure' below. # the test setup ought to be refactored. It might well use MiniTest or something. if Process.uid == 0 |