diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-11-05 19:15:40 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-25 11:42:55 +0100 |
commit | 593e6c90b7a443f77236adfa3372f65c94cfb253 (patch) | |
tree | 33507628b8d3a3e95a5b8682ad1be49961887f62 | |
parent | 950437eecd6048dd29eb3e11f4343372b2ddce60 (diff) | |
download | uci-593e6c90b7a443f77236adfa3372f65c94cfb253.tar.gz |
file: raise parse error on conflicting section types in strict mode
If strict mode is enabled and we're parsing a config file with multiple
sections of the same name but different types, then raise a parse error
to notify the user that the subsequent section declaration would shadow
all prior ones of the same name.
The error would be triggered by a config like that:
config typeA example
option test 1
config typeB example
option test 2
In such a case, libuci will raise this error:
uci: Parse error (section of different type overwrites prior section with same name) at line 4, byte 23
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r-- | file.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -437,8 +437,13 @@ static void uci_parse_config(struct uci_context *ctx) } else { uci_fill_ptr(ctx, &ptr, &pctx->package->e); e = uci_lookup_list(&pctx->package->sections, name); - if (e) + if (e) { ptr.s = uci_to_section(e); + + if ((ctx->flags & UCI_FLAG_STRICT) && strcmp(ptr.s->type, type)) + uci_parse_error(ctx, "section of different type overwrites prior section with same name"); + } + ptr.section = name; ptr.value = type; |