* the appropriate 'package <name>' string to specify the config name
* NB: the config file can still override the package name
*/
- if (name)
+ if (name) {
+ UCI_ASSERT(ctx, uci_validate_name(name));
pctx->name = name;
+ }
while (!feof(pctx->file)) {
uci_getln(ctx, 0);
}
UCI_INTERNAL(uci_parse_tuple, ctx, buf, &package, §ion, &option, &value);
- if (!package || !section || (!delete && !value))
- goto error;
- if (strcmp(package, p->e.name) != 0)
+ if (!package || (strcmp(package, p->e.name) != 0))
goto error;
if (!uci_validate_name(section))
goto error;
if (option && !uci_validate_name(option))
goto error;
+ if ((rename || !delete) && !uci_validate_name(value))
+ goto error;
if (rename)
UCI_INTERNAL(uci_rename, ctx, p, section, option, value);
if (!p->confdir)
return;
+
if ((asprintf(&filename, "%s/%s", UCI_SAVEDIR, p->e.name) < 0) || !filename)
UCI_THROW(ctx, UCI_ERR_MEM);
{
char *filename;
- if (strchr(name, '/'))
- UCI_THROW(ctx, UCI_ERR_INVAL);
+ UCI_ASSERT(ctx, uci_validate_name(name));
filename = uci_malloc(ctx, strlen(name) + sizeof(UCI_CONFDIR) + 2);
sprintf(filename, UCI_CONFDIR "/%s", name);
break;
default:
/* config in /etc/config */
- UCI_ASSERT(ctx, uci_validate_name(name));
filename = uci_config_path(ctx, name);
confdir = true;
break;
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, res != NULL);
UCI_ASSERT(ctx, p != NULL);
- UCI_ASSERT(ctx, section != NULL);
+ UCI_ASSERT(ctx, uci_validate_name(section));
+ if (option)
+ UCI_ASSERT(ctx, uci_validate_name(option));
e = uci_lookup_list(ctx, &p->sections, section);
if (!e)
int size;
UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, value != NULL);
- UCI_ASSERT(ctx, element != NULL);
- UCI_ASSERT(ctx, *element != NULL);
+ UCI_ASSERT(ctx, (element != NULL) && (*element != NULL));
/* what the 'value' of an element means depends on the type
* for a section, the 'value' means its type
list = e->list.prev;
switch(e->type) {
case UCI_TYPE_SECTION:
+ UCI_ASSERT(ctx, uci_validate_name(value));
size = sizeof(struct uci_section);
s = uci_to_section(e);
section = e->name;
option = NULL;
break;
case UCI_TYPE_OPTION:
+ UCI_ASSERT(ctx, value != NULL);
size = sizeof(struct uci_option);
s = uci_to_option(e)->section;
section = s->e.name;
struct uci_element *e;
UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, p != NULL);
- UCI_ASSERT(ctx, section != NULL);
+ /* NB: p, section, option validated by uci_lookup */
UCI_INTERNAL(uci_lookup, ctx, &e, p, section, option);
if (!internal)
struct uci_element *e;
UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, p != NULL);
- UCI_ASSERT(ctx, section != NULL);
+ /* NB: p, section, option validated by uci_lookup */
UCI_INTERNAL(uci_lookup, ctx, &e, p, section, option);
if (!internal)
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, p != NULL);
- UCI_ASSERT(ctx, section != NULL);
- UCI_ASSERT(ctx, value != NULL);
+ UCI_ASSERT(ctx, uci_validate_name(section));
+ if (option) {
+ UCI_ASSERT(ctx, uci_validate_name(option));
+ UCI_ASSERT(ctx, value != NULL);
+ } else {
+ UCI_ASSERT(ctx, uci_validate_name(value));
+ }
/*
* look up the package, section and option (if set)