1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-20 14:03:39 +03:00

varlink: improve compat with varlink C reference implementation

The reference implementation seems to set the 'parameters' field for
method calls to 'null' if nothing is specified on its command line. We
so far only could deal if the parameters field was unset or set to the
empty object. Let's also accept the 'null' type.

(cherry picked from commit f2ad89248b2177119b75bf82be69716166243996)
(cherry picked from commit 2dab8bce02123dc37f4befee16d28da390c3ddd3)
(cherry picked from commit 8760f4c9fe95a3d77af49c8920b82e996d2cdf95)
This commit is contained in:
Lennart Poettering 2023-12-01 17:59:49 +01:00 committed by Luca Boccassi
parent 460ce98eef
commit 002adef4e7

View File

@ -678,12 +678,25 @@ static int varlink_dispatch_disconnect(Varlink *v) {
} }
static int varlink_sanitize_parameters(JsonVariant **v) { static int varlink_sanitize_parameters(JsonVariant **v) {
int r;
assert(v); assert(v);
/* Varlink always wants a parameters list, hence make one if the caller doesn't want any */ /* Varlink always wants a parameters list, hence make one if the caller doesn't want any */
if (!*v) if (!*v)
return json_variant_new_object(v, NULL, 0); return json_variant_new_object(v, NULL, 0);
else if (!json_variant_is_object(*v)) if (json_variant_is_null(*v)) {
JsonVariant *empty;
r = json_variant_new_object(&empty, NULL, 0);
if (r < 0)
return r;
json_variant_unref(*v);
*v = empty;
return 0;
}
if (!json_variant_is_object(*v))
return -EINVAL; return -EINVAL;
return 0; return 0;
@ -723,7 +736,7 @@ static int varlink_dispatch_reply(Varlink *v) {
} else if (streq(k, "parameters")) { } else if (streq(k, "parameters")) {
if (parameters) if (parameters)
goto invalid; goto invalid;
if (!json_variant_is_object(e)) if (!json_variant_is_object(e) && !json_variant_is_null(e))
goto invalid; goto invalid;
parameters = json_variant_ref(e); parameters = json_variant_ref(e);
@ -822,7 +835,7 @@ static int varlink_dispatch_method(Varlink *v) {
} else if (streq(k, "parameters")) { } else if (streq(k, "parameters")) {
if (parameters) if (parameters)
goto invalid; goto invalid;
if (!json_variant_is_object(e)) if (!json_variant_is_object(e) && !json_variant_is_null(e))
goto invalid; goto invalid;
parameters = json_variant_ref(e); parameters = json_variant_ref(e);