Signed-off-by: Felix Fietkau <nbd@openwrt.org>
/*
* extract the next argument from the command line
*/
/*
* extract the next argument from the command line
*/
-static int next_arg(struct uci_context *ctx, bool required, bool name)
+static int next_arg(struct uci_context *ctx, bool required, bool name, bool package)
{
struct uci_parse_context *pctx = ctx->pctx;
int val, ptr;
{
struct uci_parse_context *pctx = ctx->pctx;
int val, ptr;
- if (name && !uci_validate_name(pctx_str(pctx, val)))
+ if (name && !uci_validate_str(pctx_str(pctx, val), name, package))
uci_parse_error(ctx, "invalid character in name field");
done:
uci_parse_error(ctx, "invalid character in name field");
done:
uci_getln(ctx, 0);
/*FIXME do we need to skip empty lines? */
uci_getln(ctx, 0);
/*FIXME do we need to skip empty lines? */
- ofs_result = next_arg(ctx, false, false);
+ ofs_result = next_arg(ctx, false, false, false);
*result = pctx_str(ctx->pctx, ofs_result);
*str = pctx_cur_str(ctx->pctx);
*result = pctx_str(ctx->pctx, ofs_result);
*str = pctx_cur_str(ctx->pctx);
int ofs_tmp;
skip_whitespace(ctx);
int ofs_tmp;
skip_whitespace(ctx);
- ofs_tmp = next_arg(ctx, false, false);
+ ofs_tmp = next_arg(ctx, false, false, false);
tmp = pctx_str(ctx->pctx, ofs_tmp);
if (*tmp && (ctx->flags & UCI_FLAG_STRICT))
uci_parse_error(ctx, "too many arguments");
tmp = pctx_str(ctx->pctx, ofs_tmp);
if (*tmp && (ctx->flags & UCI_FLAG_STRICT))
uci_parse_error(ctx, "too many arguments");
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
- ofs_name = next_arg(ctx, true, true);
+ ofs_name = next_arg(ctx, true, true, true);
name = pctx_str(pctx, ofs_name);
assert_eol(ctx);
if (single)
name = pctx_str(pctx, ofs_name);
assert_eol(ctx);
if (single)
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
- ofs_type = next_arg(ctx, true, false);
+ ofs_type = next_arg(ctx, true, false, false);
type = pctx_str(pctx, ofs_type);
if (!uci_validate_type(type))
uci_parse_error(ctx, "invalid character in type field");
type = pctx_str(pctx, ofs_type);
if (!uci_validate_type(type))
uci_parse_error(ctx, "invalid character in type field");
- ofs_name = next_arg(ctx, false, true);
+ ofs_name = next_arg(ctx, false, true, false);
type = pctx_str(pctx, ofs_type);
name = pctx_str(pctx, ofs_name);
assert_eol(ctx);
type = pctx_str(pctx, ofs_type);
name = pctx_str(pctx, ofs_name);
assert_eol(ctx);
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
/* command string null-terminated by strtok */
pctx->pos += strlen(pctx_cur_str(pctx)) + 1;
- ofs_name = next_arg(ctx, true, true);
- ofs_value = next_arg(ctx, false, false);
+ ofs_name = next_arg(ctx, true, true, false);
+ ofs_value = next_arg(ctx, false, false, false);
name = pctx_str(pctx, ofs_name);
value = pctx_str(pctx, ofs_value);
assert_eol(ctx);
name = pctx_str(pctx, ofs_name);
value = pctx_str(pctx, ofs_value);
assert_eol(ctx);
config 'type' 'section'
option 'opt' 'val'
config 'type' 'section'
option 'opt' 'val'
test_import ()
{
${UCI} import < ${REF_DIR}/import.data
test_import ()
{
${UCI} import < ${REF_DIR}/import.data
- assertSameFile ${REF_DIR}/import.result ${CONFIG_DIR}/import
+ assertSameFile ${REF_DIR}/import.result ${CONFIG_DIR}/import-test
__private void *uci_malloc(struct uci_context *ctx, size_t size);
__private void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size);
__private char *uci_strdup(struct uci_context *ctx, const char *str);
__private void *uci_malloc(struct uci_context *ctx, size_t size);
__private void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size);
__private char *uci_strdup(struct uci_context *ctx, const char *str);
-__private bool uci_validate_str(const char *str, bool name);
+__private bool uci_validate_str(const char *str, bool name, bool package);
__private void uci_add_delta(struct uci_context *ctx, struct uci_list *list, int cmd, const char *section, const char *option, const char *value);
__private void uci_free_delta(struct uci_delta *h);
__private struct uci_package *uci_alloc_package(struct uci_context *ctx, const char *name);
__private void uci_add_delta(struct uci_context *ctx, struct uci_list *list, int cmd, const char *section, const char *option, const char *value);
__private void uci_free_delta(struct uci_delta *h);
__private struct uci_package *uci_alloc_package(struct uci_context *ctx, const char *name);
static inline bool uci_validate_package(const char *str)
{
static inline bool uci_validate_package(const char *str)
{
- return uci_validate_str(str, false);
+ return uci_validate_str(str, false, true);
}
static inline bool uci_validate_type(const char *str)
{
}
static inline bool uci_validate_type(const char *str)
{
- return uci_validate_str(str, false);
+ return uci_validate_str(str, false, false);
}
static inline bool uci_validate_name(const char *str)
{
}
static inline bool uci_validate_name(const char *str)
{
- return uci_validate_str(str, true);
+ return uci_validate_str(str, true, false);
}
/* initialize a list head/item */
}
/* initialize a list head/item */
* for names, only alphanum and _ is allowed (shell compatibility)
* for types, we allow more characters
*/
* for names, only alphanum and _ is allowed (shell compatibility)
* for types, we allow more characters
*/
-__private bool uci_validate_str(const char *str, bool name)
+__private bool uci_validate_str(const char *str, bool name, bool package)
{
if (!*str)
return false;
{
if (!*str)
return false;
- if (!isalnum(c) && c != '_') {
- if (name || (c < 33) || (c > 126))
- return false;
- }
- str++;
+
+ if (isalnum(c) || c == '_')
+ continue;
+
+ if (c == '-' && package)
+ continue;
+
+ if (name || (c < 33) || (c > 126))
+ return false;