summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0e5dd73)
Improve the space separated list parser to interprete "val1 ! val2"
as ("val1", "!val2") instead of ("val1", "!", "val2").
This corrects parsing of sections like ...
config rule
option sec_ip '! 1.1.1.0/24'
... which previously errored out with:
Warning: Option @rule[0].src_ip has invalid value '!'
Fixes FS#806.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
struct uci_section *section)
{
char *p, *v;
struct uci_section *section)
{
char *p, *v;
struct uci_element *e, *l;
struct uci_option *o;
const struct fw3_option *opt;
struct uci_element *e, *l;
struct uci_option *o;
const struct fw3_option *opt;
dest = (struct list_head *)((char *)s + opt->offset);
for (p = strtok(v, " \t"); p != NULL; p = strtok(NULL, " \t"))
{
dest = (struct list_head *)((char *)s + opt->offset);
for (p = strtok(v, " \t"); p != NULL; p = strtok(NULL, " \t"))
{
+ /* If we encounter a sole "!" token, assume that it
+ * is meant to be part of the next token, so silently
+ * skip it and remember the state... */
+ if (!strcmp(p, "!"))
+ {
+ inv = true;
+ continue;
+ }
+
+ /* The previous token was a sole "!", rewind pointer
+ * back by one byte to precede the value with an
+ * exclamation mark which effectively turns
+ * ("!", "foo") into ("!foo") */
+ if (inv)
+ {
+ *--p = '!';
+ inv = false;
+ }
+
if (!opt->parse(dest, p, true))
{
warn_elem(e, "has invalid value '%s'", p);
if (!opt->parse(dest, p, true))
{
warn_elem(e, "has invalid value '%s'", p);
+
+ /* The last token was a sole "!" without any subsequent
+ * text, so pass it to the option parser as-is. */
+ if (inv && !opt->parse(dest, "!", true))
+ {
+ warn_elem(e, "has invalid value '%s'", p);
+ valid = false;
+ continue;
+ }