diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2023-03-02 17:19:36 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2023-04-26 11:00:09 +0530 |
commit | 2c4c7c8b02140ff3abb8325f6261ccf1ae18b477 (patch) | |
tree | eb823175f618dc8d059bc34eb05baba638170891 /sql | |
parent | dffd1679ba97e5e8145575f0f11cb87553670c6f (diff) | |
download | mariadb-git-2c4c7c8b02140ff3abb8325f6261ccf1ae18b477.tar.gz |
MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero
Analysis: multipleOf must be strictly greater then 0. However the
implementation only disallowed values strcitly less than 0
Fix: check if value is less than or equal to 0 instead of less than 0 and
return true.
Also fixed the incorrect return value for some other keywords.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/json_schema.cc | 41 | ||||
-rw-r--r-- | sql/json_schema.h | 2 |
2 files changed, 32 insertions, 11 deletions
diff --git a/sql/json_schema.cc b/sql/json_schema.cc index d0bb162cefe..7956ae49fff 100644 --- a/sql/json_schema.cc +++ b/sql/json_schema.cc @@ -774,7 +774,7 @@ bool Json_schema_multiple_of::validate(const json_engine_t *je, double val= je->s.cs->strntod((char *) je->value, je->value_len, &end, &err); - double temp= val / this->value; + double temp= val / multiple_of; bool res= (temp - (long long int)temp) == 0; return !res; @@ -797,12 +797,12 @@ bool Json_schema_multiple_of::handle_keyword(THD *thd, json_engine_t *je, double val= je->s.cs->strntod((char *) je->value, je->value_len, &end, &err); - if (val < 0) + if (val <= 0) { my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "multipleOf"); return true; } - value= val; + multiple_of= val; return false; } @@ -834,8 +834,11 @@ bool Json_schema_max_len::handle_keyword(THD *thd, json_engine_t *je, double val= je->s.cs->strntod((char *) je->value, je->value_len, &end, &err); if (val < 0) + { my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxLength"); - value= val; + return true; + } + value= (int)val; return false; } @@ -869,9 +872,17 @@ bool Json_schema_min_len::handle_keyword(THD *thd, json_engine_t *je, if (val < 0) { my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "minLength"); +<<<<<<< HEAD return true; } value= val; +||||||| parent of 203f63d7bf1... MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero + value= val; +======= + return true; + } + value= (int)val; +>>>>>>> 203f63d7bf1... MDEV-30704: JSON_SCHEMA_VALID: multipleOf must be greater than zero return false; } @@ -982,8 +993,11 @@ bool Json_schema_max_items::handle_keyword(THD *thd, json_engine_t *je, double val= je->s.cs->strntod((char *) je->value, je->value_len, &end, &err); if (val < 0) + { my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxItems"); - value= val; + return true; + } + value= (int)val; return false; } @@ -1037,7 +1051,7 @@ bool Json_schema_min_items::handle_keyword(THD *thd, json_engine_t *je, my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxLength"); return true; } - value= val; + value= (int)val; return false; } @@ -1279,9 +1293,14 @@ bool Json_schema_prefix_items::handle_keyword(THD *thd, json_engine_t *je, char *begin, *end; int len; - if (json_read_value(je)) - return true; - begin= (char*)je->value; + if (json_read_value(je)) + return true; + if (je->value_type != JSON_VALUE_OBJECT) + { + my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "items"); + return true; + } + begin= (char*)je->value; if (json_skip_level(je)) return true; @@ -1452,7 +1471,7 @@ bool Json_schema_max_prop::handle_keyword(THD *thd, json_engine_t *je, my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "maxProperties"); return true; } - value= val; + value= (int)val; return false; } @@ -1511,7 +1530,7 @@ bool Json_schema_min_prop::handle_keyword(THD *thd, json_engine_t *je, my_error(ER_JSON_INVALID_VALUE_FOR_KEYWORD, MYF(0), "minProperties"); return true; } - value= val; + value= (int)val; return false; } diff --git a/sql/json_schema.h b/sql/json_schema.h index 4f1e146c862..53b6aaaff9f 100644 --- a/sql/json_schema.h +++ b/sql/json_schema.h @@ -227,6 +227,8 @@ class Json_schema_minimum : public Json_schema_keyword class Json_schema_multiple_of : public Json_schema_keyword { + private: + double multiple_of; public: bool validate(const json_engine_t *je, const uchar *k_start= NULL, const uchar *k_end= NULL) override; |