diff options
author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2022-04-08 10:25:45 +0100 |
---|---|---|
committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2022-04-08 10:25:45 +0100 |
commit | 8f96bb4b259b96b3ec004a50686c771811827a83 (patch) | |
tree | 0c3546320afcb6cd04410c2e9dcaf254bf629b73 | |
parent | Remove seemingly pointless 'Run' class (diff) | |
download | netfs-8f96bb4b259b96b3ec004a50686c771811827a83.tar.bz2 netfs-8f96bb4b259b96b3ec004a50686c771811827a83.tar.xz netfs-8f96bb4b259b96b3ec004a50686c771811827a83.zip |
Fix crash when daemon receives a user or group it can't mapnetfs-1.4.2
-rw-r--r-- | netfs/daemon/modeCheck.cpp | 14 | ||||
-rw-r--r-- | netfs/unittests/Jamfile.jam | 8 | ||||
-rw-r--r-- | netfs/unittests/testDaemon.cpp | 28 |
3 files changed, 48 insertions, 2 deletions
diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index d63163a..652d8a4 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -1,10 +1,20 @@ #include "modeCheck.h" #include <exceptions.h> +template<typename Ex, typename T, typename... ExP> +T && +assert_truthy(T && v, ExP &&... p) +{ + if (!v) { + throw Ex {std::forward<ExP>(p)...}; + } + return std::forward<T>(v); +} + ModeCheck::ModeCheck(const NetFS::ReqEnv & re, const std::filesystem::path & r, const EntryResolver<User> & u, const EntryResolver<Group> & g) : - myu(u.getEntry(re.user)->id), - myg(g.getEntry(re.grp)->id), root(r), userLookup(u), groupLookup(g) + myu(assert_truthy<NetFS::SystemError>(u.getEntry(re.user), EPERM)->id), + myg(assert_truthy<NetFS::SystemError>(g.getEntry(re.grp), EPERM)->id), root(r), userLookup(u), groupLookup(g) { } diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index e811c57..1cd7d84 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -91,3 +91,11 @@ run testFuse.cpp <dependency>testCore ; +run testDaemon.cpp ../daemon/modeCheck.cpp + : -- : : + <define>BOOST_TEST_DYN_LINK + <library>boost_utf + <library>testMocks + <dependency>testCore + ; + diff --git a/netfs/unittests/testDaemon.cpp b/netfs/unittests/testDaemon.cpp new file mode 100644 index 0000000..5c6fbc9 --- /dev/null +++ b/netfs/unittests/testDaemon.cpp @@ -0,0 +1,28 @@ +#define BOOST_TEST_MODULE TestNetFSDaemon +#include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> + +#include <entCache.h> +#include <exceptions.h> +#include <modeCheck.h> + +struct ModeCheckHelper { + EntryResolverPtr<User> eru = std::make_shared<UserEntCache>(); + EntryResolverPtr<Group> erg = std::make_shared<GroupEntCache>(eru); +}; + +BOOST_FIXTURE_TEST_SUITE(mc, ModeCheckHelper) + +BOOST_AUTO_TEST_CASE(mode_check_valid) +{ + ModeCheck mc {{"root", "root"}, "/tmp", *eru, *erg}; +} + +BOOST_AUTO_TEST_CASE(mode_check_invalid) +{ + BOOST_CHECK_THROW({ ModeCheck({"root", ""}, "/tmp", *eru, *erg); }, NetFS::SystemError); + BOOST_CHECK_THROW({ ModeCheck({"", "root"}, "/tmp", *eru, *erg); }, NetFS::SystemError); + BOOST_CHECK_THROW({ ModeCheck({"", ""}, "/tmp", *eru, *erg); }, NetFS::SystemError); +} + +BOOST_AUTO_TEST_SUITE_END() |