/*
* extract the next argument from the command line
*/
-static char *next_arg(struct uci_context *ctx, char **str, bool required)
+static char *next_arg(struct uci_context *ctx, char **str, bool required, bool name)
{
char *val;
char *ptr;
parse_str(ctx, str, &ptr);
if (required && !*val)
uci_parse_error(ctx, *str, "insufficient arguments");
+ if (name && !uci_validate_name(val))
+ uci_parse_error(ctx, val, "invalid character in field");
return val;
}
{
char *tmp;
- tmp = next_arg(ctx, str, false);
+ tmp = next_arg(ctx, str, false, false);
if (tmp && *tmp)
uci_parse_error(ctx, *str, "too many arguments");
}
/* command string null-terminated by strtok */
*str += strlen(*str) + 1;
- name = next_arg(ctx, str, true);
+ name = next_arg(ctx, str, true, true);
assert_eol(ctx, str);
if (single)
return;
/* command string null-terminated by strtok */
*str += strlen(*str) + 1;
- type = next_arg(ctx, str, true);
- name = next_arg(ctx, str, false);
+ type = next_arg(ctx, str, true, true);
+ name = next_arg(ctx, str, false, true);
assert_eol(ctx, str);
ctx->pctx->section = uci_alloc_section(ctx->pctx->package, type, name);
}
/* command string null-terminated by strtok */
*str += strlen(*str) + 1;
- name = next_arg(ctx, str, true);
- value = next_arg(ctx, str, true);
+ name = next_arg(ctx, str, true, true);
+ value = next_arg(ctx, str, true, false);
assert_eol(ctx, str);
uci_alloc_option(ctx->pctx->section, name, value);
}
return ptr;
}
-static bool validate_name(char *str)
+static bool uci_validate_name(char *str)
{
if (!*str)
return false;
UCI_ASSERT(ctx, str && package && section && option);
*package = strtok(str, ".");
- if (!*package || !validate_name(*package))
+ if (!*package || !uci_validate_name(*package))
goto error;
last = *package;
goto error;
}
- if (*section && !validate_name(*section))
+ if (*section && !uci_validate_name(*section))
goto error;
- if (*option && !validate_name(*option))
+ if (*option && !uci_validate_name(*option))
goto error;
goto done;