From 3cd97c356839bf462fd4585fc06e06b40c0ce0b9 Mon Sep 17 00:00:00 2001 From: benrubson Date: Thu, 10 Aug 2017 12:18:46 +0200 Subject: [PATCH] Check (not entirely yet) read and write return codes --- .travis.yml | 6 +++++- encfs/RawFileIO.cpp | 7 +++++-- integration/normal.t.pl | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5bd591f..f763982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,11 @@ dist: trusty language: cpp -sudo: true +sudo: required + +env: + global: + - SUDO_MOUNT=sudo os: - linux diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index 27aa021..886ab87 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -202,11 +202,13 @@ ssize_t RawFileIO::read(const IORequest &req) const { rAssert(fd >= 0); ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset); + int eno = errno; + errno = 0; //just to be sure error seen in integration tests really comes from the function rc. if (readSize < 0) { - readSize = -errno; RLOG(WARNING) << "read failed at offset " << req.offset << " for " - << req.dataLen << " bytes: " << strerror(-readSize); + << req.dataLen << " bytes: " << strerror(eno); + return -eno; } return readSize; @@ -226,6 +228,7 @@ ssize_t RawFileIO::write(const IORequest &req) { errno = 0; ssize_t writeSize = ::pwrite(fd, buf, bytes, offset); eno = errno; + errno = 0; //just to be sure error seen in integration tests really comes from the function rc. if (writeSize < 0) { knownSize = false; diff --git a/integration/normal.t.pl b/integration/normal.t.pl index 3d184ad..9da2d5a 100755 --- a/integration/normal.t.pl +++ b/integration/normal.t.pl @@ -2,7 +2,7 @@ # Test EncFS normal and paranoid mode -use Test::More tests => 122; +use Test::More tests => 132; use File::Path; use File::Copy; use File::Temp; @@ -78,6 +78,8 @@ sub runTests &grow; &umask0777; &create_unmount_remount; + &checkReadError; + &checkWriteError; &configFromPipe; &cleanup; @@ -430,3 +432,38 @@ sub create_unmount_remount portable_unmount($mnt); } + +# Test that read errors are correctly thrown up to us +sub checkReadError +{ + # Not sure how to implement this, so feel free ! + ok(1, "read error"); +} + +# Test that write errors are correctly thrown up to us +sub checkWriteError +{ + # Not sure how to implement this on Mac OS, so feel free ! + if($^O eq "darwin") { + ok(1, "write error"); + ok(1, "write error"); + ok(1, "write error"); + ok(1, "write error"); + } + else { + my $crypt = "$workingDir/checkWriteError.crypt"; + my $mnt = "$workingDir/checkWriteError.mnt"; + mkdir($crypt) || BAIL_OUT($!); + mkdir($mnt) || BAIL_OUT($!); + system(($ENV{'SUDO_MOUNT'}||"")." mount -t tmpfs -o size=1m tmpfs $crypt"); + ok( $? == 0, "mount command returns 0") || return; + system("./build/encfs --standard --extpass=\"echo test\" $crypt $mnt 2>&1"); + ok( $? == 0, "encfs command returns 0") || return; + ok(open(OUT , "> $mnt/file"), "write content"); + while(print OUT "0123456789") {} + ok ($!{ENOSPC}, "write returned $! instead of ENOSPC"); + close OUT; + portable_unmount($mnt); + system(($ENV{'SUDO_MOUNT'}||"")." umount $crypt"); + } +}