diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-10-11 20:49:19 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-10-11 20:49:19 +0200 |
commit | f69dc9a3d1e48fbb91a68c1dd85de9a7c3fcbbe0 (patch) | |
tree | c89afab01fea21458d15ca48ecace4e601588c24 /src/libsystemd-bus | |
parent | 77a874a3fb6f65d2308c20827f005c43bb075752 (diff) |
bus: beef up parameter checking of convenience calls
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r-- | src/libsystemd-bus/bus-convenience.c | 95 |
1 files changed, 42 insertions, 53 deletions
diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c index 3d223c03a8..ddde5da163 100644 --- a/src/libsystemd-bus/bus-convenience.c +++ b/src/libsystemd-bus/bus-convenience.c @@ -33,12 +33,9 @@ int sd_bus_emit_signal( _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; - if (!bus) - return -EINVAL; - if (!BUS_IS_OPEN(bus->state)) - return -ENOTCONN; - if (bus_pid_changed(bus)) - return -ECHILD; + assert_return(bus, -EINVAL); + assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + assert_return(!bus_pid_changed(bus), -ECHILD); r = sd_bus_message_new_signal(bus, path, interface, member, &m); if (r < 0) @@ -70,13 +67,9 @@ int sd_bus_call_method( _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; - if (!bus) - - return -EINVAL; - if (!BUS_IS_OPEN(bus->state)) - return -ENOTCONN; - if (bus_pid_changed(bus)) - return -ECHILD; + assert_return(bus, -EINVAL); + assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + assert_return(!bus_pid_changed(bus), -ECHILD); r = sd_bus_message_new_method_call(bus, destination, path, interface, member, &m); if (r < 0) @@ -103,18 +96,12 @@ int sd_bus_reply_method_return( _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; - if (!bus) - return -EINVAL; - if (!call) - return -EINVAL; - if (!call->sealed) - return -EPERM; - 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; + 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; @@ -144,20 +131,13 @@ int sd_bus_reply_method_error( _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r; - if (!bus) - return -EINVAL; - if (!call) - return -EINVAL; - if (!call->sealed) - return -EPERM; - if (call->header->type != SD_BUS_MESSAGE_TYPE_METHOD_CALL) - 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; + 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(sd_bus_error_is_set(e), -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; @@ -180,6 +160,16 @@ int sd_bus_reply_method_errorf( va_list ap; 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); if (!error.name) return -ENOMEM; @@ -211,14 +201,13 @@ int sd_bus_get_property( sd_bus_message *rep = NULL; int r; - if (interface && !interface_name_is_valid(interface)) - return -EINVAL; - if (!member_name_is_valid(member)) - return -EINVAL; - if (!signature_is_single(type, false)) - return -EINVAL; - if (!reply) - return -EINVAL; + assert_return(bus, -EINVAL); + assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL); + assert_return(member_name_is_valid(member), -EINVAL); + assert_return(reply, -EINVAL); + assert_return(signature_is_single(type, false), -EINVAL); + assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + assert_return(!bus_pid_changed(bus), -ECHILD); r = sd_bus_call_method(bus, destination, path, "org.freedesktop.DBus.Properties", "Get", error, &rep, "ss", strempty(interface), member); if (r < 0) @@ -247,12 +236,12 @@ int sd_bus_set_property( va_list ap; int r; - if (interface && !interface_name_is_valid(interface)) - return -EINVAL; - if (!member_name_is_valid(member)) - return -EINVAL; - if (!signature_is_single(type, false)) - return -EINVAL; + assert_return(bus, -EINVAL); + assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL); + assert_return(member_name_is_valid(member), -EINVAL); + assert_return(signature_is_single(type, false), -EINVAL); + assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN); + assert_return(!bus_pid_changed(bus), -ECHILD); r = sd_bus_message_new_method_call(bus, destination, path, "org.freedesktop.DBus.Properties", "Set", &m); if (r < 0) |