varlink: allow strings for integer varlink IDL fields

This is a follow-up for 67a3028555: also
allow strings as integer during IDL validation of JSON records.
This commit is contained in:
Lennart Poettering
2024-03-04 19:47:26 +00:00
committed by Luca Boccassi
parent a7839bff68
commit 217f63c9b8
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -1379,7 +1379,8 @@ static int varlink_idl_validate_field_element_type(const VarlinkField *field, Js
break;
case VARLINK_INT:
if (!json_variant_is_integer(v) && !json_variant_is_unsigned(v))
/* Allow strings here too, since integers with > 53 bits are often passed in as strings */
if (!json_variant_is_integer(v) && !json_variant_is_unsigned(v) && !json_variant_is_string(v))
return varlink_idl_log(SYNTHETIC_ERRNO(EMEDIUMTYPE), "Field '%s' should be an int, but it is not, refusing.", strna(field->name));
break;
+1 -1
View File
@@ -385,7 +385,7 @@ TEST(validate_method_call) {
assert_se(varlink_callb(v, "xyz.TestMethod", &reply, &error_id,
JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("foo", "wuff"),
JSON_BUILD_PAIR_BOOLEAN("foo", true),
JSON_BUILD_PAIR_UNSIGNED("bar", 9))) >= 0);
assert_se(streq_ptr(error_id, VARLINK_ERROR_INVALID_PARAMETER));