mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-22 18:01:12 +08:00
Add proper input validation for readdir policy
This commit is contained in:
parent
69de4de53f
commit
335ca55a6e
@ -81,6 +81,9 @@ FUSE::ReadDir::from_string(std::string const &str_)
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lg(_mutex);
|
std::lock_guard<std::mutex> lg(_mutex);
|
||||||
|
|
||||||
|
if(!FUSE::ReadDirFactory::valid(str_))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
_type = str_;
|
_type = str_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,13 +26,14 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
namespace l
|
namespace l
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
read_cfg(std::string const cfgstr_,
|
read_cfg(std::string const str_,
|
||||||
std::string &type_,
|
std::string &type_,
|
||||||
int &concurrency_)
|
int &concurrency_)
|
||||||
{
|
{
|
||||||
@ -40,7 +41,7 @@ namespace l
|
|||||||
int concurrency;
|
int concurrency;
|
||||||
|
|
||||||
concurrency = 0;
|
concurrency = 0;
|
||||||
std::sscanf(cfgstr_.c_str(),"%15[a-z]:%u",type,&concurrency);
|
std::sscanf(str_.c_str(),"%15[a-z]:%d",type,&concurrency);
|
||||||
|
|
||||||
if(concurrency == 0)
|
if(concurrency == 0)
|
||||||
concurrency = std::thread::hardware_concurrency();
|
concurrency = std::thread::hardware_concurrency();
|
||||||
@ -55,14 +56,36 @@ namespace l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
FUSE::ReadDirFactory::valid(std::string const str_)
|
||||||
|
{
|
||||||
|
int concurrency;
|
||||||
|
std::string type;
|
||||||
|
static const std::set<std::string> types =
|
||||||
|
{
|
||||||
|
"seq", "cosr", "cor"
|
||||||
|
};
|
||||||
|
|
||||||
|
l::read_cfg(str_,type,concurrency);
|
||||||
|
|
||||||
|
if(types.find(type) == types.end())
|
||||||
|
return false;
|
||||||
|
if(concurrency <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<FUSE::ReadDirBase>
|
std::shared_ptr<FUSE::ReadDirBase>
|
||||||
FUSE::ReadDirFactory::make(std::string const cfgstr_)
|
FUSE::ReadDirFactory::make(std::string const str_)
|
||||||
{
|
{
|
||||||
int concurrency;
|
int concurrency;
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
||||||
l::read_cfg(cfgstr_,type,concurrency);
|
if(!valid(str_))
|
||||||
assert(concurrency);
|
return {};
|
||||||
|
|
||||||
|
l::read_cfg(str_,type,concurrency);
|
||||||
|
|
||||||
if(type == "seq")
|
if(type == "seq")
|
||||||
return std::make_shared<FUSE::ReadDirSeq>();
|
return std::make_shared<FUSE::ReadDirSeq>();
|
||||||
|
@ -29,6 +29,7 @@ namespace FUSE
|
|||||||
class ReadDirFactory
|
class ReadDirFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<ReadDirBase> make(std::string const cfgstr);
|
static bool valid(std::string str);
|
||||||
|
static std::shared_ptr<ReadDirBase> make(std::string const str);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user