Do not ignore setting of wrong command line options
Options passed through --json-interface or --xml-interface bypassed validation.
This commit is contained in:
parent
688b90a52e
commit
dba23e1268
|
@ -0,0 +1,6 @@
|
|||
CORE broken-smt-backend
|
||||
--json-interface
|
||||
< test_wrong_flag.json
|
||||
^EXIT=6$
|
||||
^SIGNAL=0$
|
||||
unknown command line option
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"arguments": [
|
||||
"main.c"
|
||||
],
|
||||
"options": {
|
||||
"function": "foo",
|
||||
"unwind": 3,
|
||||
"property": [
|
||||
"foo.assertion.1",
|
||||
"foo.assertion.3"
|
||||
],
|
||||
"unknown-flag": true,
|
||||
"show-properties": false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
CORE broken-smt-backend
|
||||
--json-interface
|
||||
< test_wrong_option.json
|
||||
^EXIT=6$
|
||||
^SIGNAL=0$
|
||||
unknown command line option
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"arguments": [
|
||||
"main.c"
|
||||
],
|
||||
"options": {
|
||||
"function": "foo",
|
||||
"unwind": 3,
|
||||
"unknown-option": [
|
||||
"foo.assertion.1",
|
||||
"foo.assertion.3"
|
||||
],
|
||||
"trace": true,
|
||||
"show-properties": false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
CORE
|
||||
--xml-interface
|
||||
< test_wrong_flag.xml
|
||||
^EXIT=6$
|
||||
^SIGNAL=0$
|
||||
unknown command line option
|
|
@ -0,0 +1,9 @@
|
|||
<options>
|
||||
<valueOption actual="main.c"/>
|
||||
<valueOption name="function" actual="foo"/>
|
||||
<valueOption name="unwind" actual="3"/>
|
||||
<valueOption name="property" actual="foo.assertion.1"/>
|
||||
<valueOption name="property" actual="foo.assertion.3"/>
|
||||
<flagOption name="trace" actual="on"/>
|
||||
<flagOption name="unknown-flag" actual="off"/>
|
||||
</options>
|
|
@ -0,0 +1,6 @@
|
|||
CORE
|
||||
--xml-interface
|
||||
< test_wrong_option.xml
|
||||
^EXIT=6$
|
||||
^SIGNAL=0$
|
||||
unknown command line option
|
|
@ -0,0 +1,9 @@
|
|||
<options>
|
||||
<valueOption actual="main.c"/>
|
||||
<valueOption name="function" actual="foo"/>
|
||||
<valueOption name="unknown-option" actual="3"/>
|
||||
<valueOption name="property" actual="foo.assertion.1"/>
|
||||
<valueOption name="property" actual="foo.assertion.3"/>
|
||||
<flagOption name="trace" actual="on"/>
|
||||
<flagOption name="show-properties" actual="off"/>
|
||||
</options>
|
|
@ -8,6 +8,7 @@ Author: Daniel Kroening, kroening@kroening.com
|
|||
|
||||
#include "cmdline.h"
|
||||
|
||||
#include <util/exception_utils.h>
|
||||
#include <util/invariant.h>
|
||||
|
||||
cmdlinet::cmdlinet()
|
||||
|
@ -58,8 +59,11 @@ void cmdlinet::set(const std::string &option, bool value)
|
|||
|
||||
if(i.has_value())
|
||||
options[*i].isset = value;
|
||||
|
||||
// otherwise ignore
|
||||
else
|
||||
{
|
||||
throw invalid_command_line_argument_exceptiont(
|
||||
"unknown command line option", option);
|
||||
}
|
||||
}
|
||||
|
||||
void cmdlinet::set(const std::string &option, const std::string &value)
|
||||
|
@ -71,8 +75,11 @@ void cmdlinet::set(const std::string &option, const std::string &value)
|
|||
options[*i].isset=true;
|
||||
options[*i].values.push_back(value);
|
||||
}
|
||||
|
||||
// otherwise ignore
|
||||
else
|
||||
{
|
||||
throw invalid_command_line_argument_exceptiont(
|
||||
"unknown command line option", option);
|
||||
}
|
||||
}
|
||||
|
||||
static std::list<std::string> immutable_empty_list;
|
||||
|
|
|
@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
|
|||
#include <iostream>
|
||||
|
||||
#include <util/cmdline.h>
|
||||
#include <util/exception_utils.h>
|
||||
#include <util/message.h>
|
||||
|
||||
#include <xmllang/xml_parser.h>
|
||||
|
@ -51,6 +52,10 @@ void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
|
|||
|
||||
parse_xml(std::cin, "", message_handler, xml);
|
||||
|
||||
// We have to catch here because command line options are
|
||||
// parsed in the constructor of parse_optionst and not in main()
|
||||
try
|
||||
{
|
||||
get_xml_options(xml, cmdline);
|
||||
|
||||
// Add this so that it gets propagated into optionst;
|
||||
|
@ -58,4 +63,13 @@ void xml_interface(cmdlinet &cmdline, message_handlert &message_handler)
|
|||
// of the xml-interface flag.
|
||||
cmdline.set("xml-ui");
|
||||
}
|
||||
catch(const invalid_command_line_argument_exceptiont &e)
|
||||
{
|
||||
messaget log(message_handler);
|
||||
log.error() << e.what() << messaget::eom;
|
||||
|
||||
// make sure we fail with a usage error
|
||||
cmdline.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue