aboutsummaryrefslogtreecommitdiff
path: root/src/qt/rpcconsole.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-12-19 09:08:00 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-12-19 09:08:20 +0100
commitdb45ad85164d84790ab3d30f393d44d8fed6edad (patch)
tree7464c8e9a9672e36a60a44bfff1dcbf4bbb4247d /src/qt/rpcconsole.cpp
parenta7f76512d9eacddd96f291de5ba08697e68018d9 (diff)
parent390bd14684a4f1a974014a31c71d44acd3d94d6a (diff)
Merge #9329: [Qt] Console: allow empty arguments
390bd14 [Qt] Console: don't allow empty arguments when using the comma-syntax (Jonas Schnelli) 6a32c0f Qt/Test: Check handling of empty arguments in RPC debug console (Luke Dashjr) 89c8d2c [Qt] Console: allow empty arguments (Jonas Schnelli)
Diffstat (limited to 'src/qt/rpcconsole.cpp')
-rw-r--r--src/qt/rpcconsole.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index 4ba2f2615f..cfe197de2a 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -137,6 +137,8 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
enum CmdParseState
{
STATE_EATING_SPACES,
+ STATE_EATING_SPACES_IN_ARG,
+ STATE_EATING_SPACES_IN_BRACKETS,
STATE_ARGUMENT,
STATE_SINGLEQUOTED,
STATE_DOUBLEQUOTED,
@@ -220,6 +222,8 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
break;
}
case STATE_ARGUMENT: // In or after argument
+ case STATE_EATING_SPACES_IN_ARG:
+ case STATE_EATING_SPACES_IN_BRACKETS:
case STATE_EATING_SPACES: // Handle runs of whitespace
switch(ch)
{
@@ -227,19 +231,20 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
case '\'': state = STATE_SINGLEQUOTED; break;
case '\\': state = STATE_ESCAPE_OUTER; break;
case '(': case ')': case '\n':
+ if (state == STATE_EATING_SPACES_IN_ARG)
+ throw std::runtime_error("Invalid Syntax");
if (state == STATE_ARGUMENT)
{
if (ch == '(' && stack.size() && stack.back().size() > 0)
stack.push_back(std::vector<std::string>());
- if (curarg.size())
- {
- // don't allow commands after executed commands on baselevel
- if (!stack.size())
- throw std::runtime_error("Invalid Syntax");
- stack.back().push_back(curarg);
- }
+
+ // don't allow commands after executed commands on baselevel
+ if (!stack.size())
+ throw std::runtime_error("Invalid Syntax");
+
+ stack.back().push_back(curarg);
curarg.clear();
- state = STATE_EATING_SPACES;
+ state = STATE_EATING_SPACES_IN_BRACKETS;
}
if ((ch == ')' || ch == '\n') && stack.size() > 0)
{
@@ -256,12 +261,19 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
}
break;
case ' ': case ',': case '\t':
- if(state == STATE_ARGUMENT) // Space ends argument
+ if(state == STATE_EATING_SPACES_IN_ARG && curarg.empty() && ch == ',')
+ throw std::runtime_error("Invalid Syntax");
+
+ else if(state == STATE_ARGUMENT) // Space ends argument
{
- if (curarg.size())
- stack.back().push_back(curarg);
+ stack.back().push_back(curarg);
curarg.clear();
}
+ if ((state == STATE_EATING_SPACES_IN_BRACKETS || state == STATE_ARGUMENT) && ch == ',')
+ {
+ state = STATE_EATING_SPACES_IN_ARG;
+ break;
+ }
state = STATE_EATING_SPACES;
break;
default: curarg += ch; state = STATE_ARGUMENT;