mirror of https://github.com/aria2/aria2
Don't allow empty string for --rpc-secret option
parent
de4cd8b59b
commit
1a24020e63
|
@ -875,11 +875,12 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
|||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
OptionHandler* op(new DefaultOptionHandler
|
||||
(PREF_RPC_SECRET,
|
||||
TEXT_RPC_SECRET));
|
||||
DefaultOptionHandler* op(new DefaultOptionHandler
|
||||
(PREF_RPC_SECRET,
|
||||
TEXT_RPC_SECRET));
|
||||
op->addTag(TAG_RPC);
|
||||
op->setEraseAfterParse(true);
|
||||
op->setAllowEmpty(false);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
{
|
||||
|
|
|
@ -287,7 +287,8 @@ DefaultOptionHandler::DefaultOptionHandler
|
|||
char shortName)
|
||||
: AbstractOptionHandler(pref, description, defaultValue, argType,
|
||||
shortName),
|
||||
possibleValuesString_(possibleValuesString)
|
||||
possibleValuesString_(possibleValuesString),
|
||||
allowEmpty_(true)
|
||||
{}
|
||||
|
||||
DefaultOptionHandler::~DefaultOptionHandler() {}
|
||||
|
@ -295,6 +296,9 @@ DefaultOptionHandler::~DefaultOptionHandler() {}
|
|||
void DefaultOptionHandler::parseArg(Option& option, const std::string& optarg)
|
||||
const
|
||||
{
|
||||
if(!allowEmpty_ && optarg.empty()) {
|
||||
throw DL_ABORT_EX("Empty string is not allowed");
|
||||
}
|
||||
option.put(pref_, optarg);
|
||||
}
|
||||
|
||||
|
@ -303,6 +307,11 @@ std::string DefaultOptionHandler::createPossibleValuesString() const
|
|||
return possibleValuesString_;
|
||||
}
|
||||
|
||||
void DefaultOptionHandler::setAllowEmpty(bool allow)
|
||||
{
|
||||
allowEmpty_ = allow;
|
||||
}
|
||||
|
||||
CumulativeOptionHandler::CumulativeOptionHandler
|
||||
(PrefPtr pref,
|
||||
const char* description,
|
||||
|
|
|
@ -127,6 +127,7 @@ public:
|
|||
class DefaultOptionHandler : public AbstractOptionHandler {
|
||||
private:
|
||||
std::string possibleValuesString_;
|
||||
bool allowEmpty_;
|
||||
public:
|
||||
DefaultOptionHandler(PrefPtr pref,
|
||||
const char* description = NO_DESCRIPTION,
|
||||
|
@ -138,6 +139,7 @@ public:
|
|||
virtual void parseArg(Option& option, const std::string& optarg) const
|
||||
CXX11_OVERRIDE;
|
||||
virtual std::string createPossibleValuesString() const CXX11_OVERRIDE;
|
||||
void setAllowEmpty(bool allow);
|
||||
};
|
||||
|
||||
class CumulativeOptionHandler : public AbstractOptionHandler {
|
||||
|
|
Loading…
Reference in New Issue