diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-30 18:36:51 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-09-30 18:36:51 +0100 |
commit | 5c8208c6972fb0e5880836b7957cf7dd63ac0897 (patch) | |
tree | da78389526af971bd6c9ffbcc8523977d4febdd7 /contrib | |
parent | 730eff720cba4b756e60b29664438d685b93e3fb (diff) | |
download | rspamd-5c8208c6972fb0e5880836b7957cf7dd63ac0897.tar.gz rspamd-5c8208c6972fb0e5880836b7957cf7dd63ac0897.zip |
[Minor] Backport fix from libucl
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/libucl/ucl_schema.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/contrib/libucl/ucl_schema.c b/contrib/libucl/ucl_schema.c index 4d7c871ff..d11d66909 100644 --- a/contrib/libucl/ucl_schema.c +++ b/contrib/libucl/ucl_schema.c @@ -49,7 +49,16 @@ static bool ucl_schema_validate (const ucl_object_t *schema, /* * Create validation error */ -static void + +#ifdef __GNUC__ +static inline void +ucl_schema_create_error (struct ucl_schema_error *err, + enum ucl_schema_error_code code, const ucl_object_t *obj, + const char *fmt, ...) +__attribute__ (( format( printf, 4, 5) )); +#endif + +static inline void ucl_schema_create_error (struct ucl_schema_error *err, enum ucl_schema_error_code code, const ucl_object_t *obj, const char *fmt, ...) @@ -69,7 +78,7 @@ ucl_schema_create_error (struct ucl_schema_error *err, * Check whether we have a pattern specified */ static const ucl_object_t * -ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern) +ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern, bool recursive) { const ucl_object_t *res = NULL; #ifdef HAVE_REGEX_H @@ -78,11 +87,16 @@ ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern) ucl_object_iter_t iter = NULL; if (regcomp (®, pattern, REG_EXTENDED | REG_NOSUB) == 0) { - while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) { - if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) { - res = elt; - break; + if (recursive) { + while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) { + if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) { + res = elt; + break; + } } + } else { + if (regexec (®, ucl_object_key (obj), 0, NULL, 0) == 0) + res = obj; } regfree (®); } @@ -205,12 +219,17 @@ ucl_schema_validate_object (const ucl_object_t *schema, } } else if (strcmp (ucl_object_key (elt), "patternProperties") == 0) { + const ucl_object_t *vobj; + ucl_object_iter_t viter; piter = NULL; while (ret && (prop = ucl_object_iterate (elt, &piter, true)) != NULL) { - found = ucl_schema_test_pattern (obj, ucl_object_key (prop)); - if (found) { - ret = ucl_schema_validate (prop, found, true, err, root, - ext_ref); + viter = NULL; + while (ret && (vobj = ucl_object_iterate (obj, &viter, true)) != NULL) { + found = ucl_schema_test_pattern (vobj, ucl_object_key (prop), false); + if (found) { + ret = ucl_schema_validate (prop, found, true, err, root, + ext_ref); + } } } } @@ -234,7 +253,7 @@ ucl_schema_validate_object (const ucl_object_t *schema, piter = NULL; pat = ucl_object_lookup (schema, "patternProperties"); while ((pelt = ucl_object_iterate (pat, &piter, true)) != NULL) { - found = ucl_schema_test_pattern (obj, ucl_object_key (pelt)); + found = ucl_schema_test_pattern (obj, ucl_object_key (pelt), true); if (found != NULL) { break; } @@ -301,7 +320,7 @@ ucl_schema_validate_number (const ucl_object_t *schema, if (fabs (remainder (val, constraint)) > alpha) { ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, "number %.4f is not multiple of %.4f, remainder is %.7f", - val, constraint); + val, constraint, remainder (val, constraint)); ret = false; break; } @@ -361,7 +380,7 @@ ucl_schema_validate_string (const ucl_object_t *schema, constraint = ucl_object_toint (elt); if (obj->len > constraint) { ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "string is too big: %.3f, maximum is: %.3f", + "string is too big: %u, maximum is: %" PRId64, obj->len, constraint); ret = false; break; @@ -372,7 +391,7 @@ ucl_schema_validate_string (const ucl_object_t *schema, constraint = ucl_object_toint (elt); if (obj->len < constraint) { ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "string is too short: %.3f, minimum is: %.3f", + "string is too short: %u, minimum is: %" PRId64, obj->len, constraint); ret = false; break; |