X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=list.c;h=ab2683c4c47d282018336b1be628f2a76b489e02;hp=66e83ec0be51151defd8475d0e5d99608a78d4a2;hb=96d35364c9159c96b164369d0d0c5147b0c73a24;hpb=1085fcb801f6e716b41d4c80942c7c802b5270b3 diff --git a/list.c b/list.c index 66e83ec..ab2683c 100644 --- a/list.c +++ b/list.c @@ -241,7 +241,9 @@ int uci_lookup(struct uci_context *ctx, struct uci_element **res, struct uci_pac 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) @@ -322,9 +324,7 @@ int uci_set_element_value(struct uci_context *ctx, struct uci_element **element, 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 @@ -339,12 +339,14 @@ int uci_set_element_value(struct uci_context *ctx, struct uci_element **element, 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; @@ -385,9 +387,8 @@ int uci_rename(struct uci_context *ctx, struct uci_package *p, char *section, ch 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) @@ -409,16 +410,12 @@ int uci_delete(struct uci_context *ctx, struct uci_package *p, char *section, ch 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) - return uci_del_element(ctx, e); - UCI_INTERNAL(uci_del_element, ctx, e); - - return 0; + ctx->internal = internal; + return uci_del_element(ctx, e); } int uci_set(struct uci_context *ctx, struct uci_package *p, char *section, char *option, char *value) @@ -431,8 +428,13 @@ int uci_set(struct uci_context *ctx, struct uci_package *p, char *section, char 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) @@ -463,11 +465,8 @@ int uci_set(struct uci_context *ctx, struct uci_package *p, char *section, char else e = &s->e; - if (!internal) - return uci_set_element_value(ctx, &e, value); - - UCI_INTERNAL(uci_set_element_value, ctx, &e, value); - return 0; + ctx->internal = internal; + return uci_set_element_value(ctx, &e, value); notfound: /*