In the procd script (/lib/functions/procd.sh) uci_validate_section is in charge
of validating the uci config files. The uci_validate_section function checks
return code of validate_data tool; without this change in case of invalid
config values the function is not able to catch errors.
Signed-off-by: Luka Perkov <luka@openwrt.org>
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
{
int i = 0;
bool empty = true, first = true;
validate_value(struct uci_ptr *ptr, const char *expr, const char *def)
{
int i = 0;
bool empty = true, first = true;
+ enum dt_type type = DT_INVALID;
struct uci_element *e;
struct uci_option *opt = ptr->o;
struct uci_element *e;
struct uci_option *opt = ptr->o;
if (empty)
{
export_value(DT_STRING, ptr->option, def);
if (empty)
{
export_value(DT_STRING, ptr->option, def);
}
uci_foreach_element(&opt->v.list, e)
}
uci_foreach_element(&opt->v.list, e)
if (!opt->v.string || !*opt->v.string)
{
export_value(DT_STRING, ptr->option, def);
if (!opt->v.string || !*opt->v.string)
{
export_value(DT_STRING, ptr->option, def);
}
type = dt_parse(expr, opt->v.string);
}
type = dt_parse(expr, opt->v.string);
ptr->package, ptr->section, ptr->option, opt->v.string,
expr, type ? "true" : "false");
}
ptr->package, ptr->section, ptr->option, opt->v.string,
expr, type ? "true" : "false");
}
validate_option(struct uci_context *ctx, char *package, char *section, char *option)
{
char *opt, *expr, *def;
validate_option(struct uci_context *ctx, char *package, char *section, char *option)
{
char *opt, *expr, *def;
if (!parse_tuple(option, &opt, &expr, &def))
{
fprintf(stderr, "%s is not a valid option\n", option);
if (!parse_tuple(option, &opt, &expr, &def))
{
fprintf(stderr, "%s is not a valid option\n", option);
(ptr.last->type != UCI_TYPE_OPTION))
{
export_value(DT_STRING, opt, def);
(ptr.last->type != UCI_TYPE_OPTION))
{
export_value(DT_STRING, opt, def);
- validate_value(&ptr, expr, def);
+ return validate_value(&ptr, expr, def);
char *opt, *expr, *def;
int len = argc - 4;
enum dt_type rv;
char *opt, *expr, *def;
int len = argc - 4;
enum dt_type rv;
if (argc == 3) {
rv = dt_parse(argv[1], argv[2]);
if (argc == 3) {
rv = dt_parse(argv[1], argv[2]);
if (uci_load(ctx, argv[1], &package))
return -1;
if (uci_load(ctx, argv[1], &package))
return -1;
- for (i = 0; i < len; i++)
- validate_option(ctx, argv[1], argv[3], argv[4 + i]);
+ rc = 0;
+ for (i = 0; i < len; i++) {
+ if (validate_option(ctx, argv[1], argv[3], argv[4 + i])) {
+ rc = -1;
+ }
+ }