mirror of
https://github.com/systemd/systemd.git
synced 2025-09-09 17:44:49 +03:00
bus: beef up parameter checking of convenience calls
This commit is contained in:
@@ -33,12 +33,9 @@ int sd_bus_emit_signal(
|
|||||||
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!bus)
|
assert_return(bus, -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
if (!BUS_IS_OPEN(bus->state))
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
return -ENOTCONN;
|
|
||||||
if (bus_pid_changed(bus))
|
|
||||||
return -ECHILD;
|
|
||||||
|
|
||||||
r = sd_bus_message_new_signal(bus, path, interface, member, &m);
|
r = sd_bus_message_new_signal(bus, path, interface, member, &m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -70,13 +67,9 @@ int sd_bus_call_method(
|
|||||||
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!bus)
|
assert_return(bus, -EINVAL);
|
||||||
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
return -EINVAL;
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
if (!BUS_IS_OPEN(bus->state))
|
|
||||||
return -ENOTCONN;
|
|
||||||
if (bus_pid_changed(bus))
|
|
||||||
return -ECHILD;
|
|
||||||
|
|
||||||
r = sd_bus_message_new_method_call(bus, destination, path, interface, member, &m);
|
r = sd_bus_message_new_method_call(bus, destination, path, interface, member, &m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -103,18 +96,12 @@ int sd_bus_reply_method_return(
|
|||||||
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!bus)
|
assert_return(bus, -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(call, -EINVAL);
|
||||||
if (!call)
|
assert_return(call->sealed, -EPERM);
|
||||||
return -EINVAL;
|
assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
|
||||||
if (!call->sealed)
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
return -EPERM;
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
|
|
||||||
return -EINVAL;
|
|
||||||
if (!BUS_IS_OPEN(bus->state))
|
|
||||||
return -ENOTCONN;
|
|
||||||
if (bus_pid_changed(bus))
|
|
||||||
return -ECHILD;
|
|
||||||
|
|
||||||
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
|
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -144,20 +131,13 @@ int sd_bus_reply_method_error(
|
|||||||
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!bus)
|
assert_return(bus, -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(call, -EINVAL);
|
||||||
if (!call)
|
assert_return(call->sealed, -EPERM);
|
||||||
return -EINVAL;
|
assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
|
||||||
if (!call->sealed)
|
assert_return(sd_bus_error_is_set(e), -EINVAL);
|
||||||
return -EPERM;
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL)
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
return -EINVAL;
|
|
||||||
if (!sd_bus_error_is_set(e))
|
|
||||||
return -EINVAL;
|
|
||||||
if (!BUS_IS_OPEN(bus->state))
|
|
||||||
return -ENOTCONN;
|
|
||||||
if (bus_pid_changed(bus))
|
|
||||||
return -ECHILD;
|
|
||||||
|
|
||||||
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
|
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -180,6 +160,16 @@ int sd_bus_reply_method_errorf(
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
assert_return(bus, -EINVAL);
|
||||||
|
assert_return(call, -EINVAL);
|
||||||
|
assert_return(call->sealed, -EPERM);
|
||||||
|
assert_return(call->header->type == SD_BUS_MESSAGE_TYPE_METHOD_CALL, -EINVAL);
|
||||||
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
|
|
||||||
|
if (call->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED)
|
||||||
|
return 0;
|
||||||
|
|
||||||
error.name = strdup(name);
|
error.name = strdup(name);
|
||||||
if (!error.name)
|
if (!error.name)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -211,14 +201,13 @@ int sd_bus_get_property(
|
|||||||
sd_bus_message *rep = NULL;
|
sd_bus_message *rep = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (interface && !interface_name_is_valid(interface))
|
assert_return(bus, -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
|
||||||
if (!member_name_is_valid(member))
|
assert_return(member_name_is_valid(member), -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(reply, -EINVAL);
|
||||||
if (!signature_is_single(type, false))
|
assert_return(signature_is_single(type, false), -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
if (!reply)
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &rep, "ss", strempty(interface), member);
|
r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &rep, "ss", strempty(interface), member);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -247,12 +236,12 @@ int sd_bus_set_property(
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (interface && !interface_name_is_valid(interface))
|
assert_return(bus, -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
|
||||||
if (!member_name_is_valid(member))
|
assert_return(member_name_is_valid(member), -EINVAL);
|
||||||
return -EINVAL;
|
assert_return(signature_is_single(type, false), -EINVAL);
|
||||||
if (!signature_is_single(type, false))
|
assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
|
||||||
return -EINVAL;
|
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||||
|
|
||||||
r = sd_bus_message_new_method_call(bus, destination, path, "org.freedesktop.DBus.Properties", "Set", &m);
|
r = sd_bus_message_new_method_call(bus, destination, path, "org.freedesktop.DBus.Properties", "Set", &m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Reference in New Issue
Block a user