From: Lennart Poettering Date: Fri, 25 Jun 2010 21:12:57 +0000 (+0200) Subject: daemon: add some minimal OOM checking against D-Bus X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=226060be021ca168aba33410b49e89a1f8bf4a00;p=catta daemon: add some minimal OOM checking against D-Bus --- diff --git a/avahi-daemon/dbus-async-address-resolver.c b/avahi-daemon/dbus-async-address-resolver.c index dcb15e7..5be08c2 100644 --- a/avahi-daemon/dbus-async-address-resolver.c +++ b/avahi-daemon/dbus-async-address-resolver.c @@ -59,6 +59,11 @@ void avahi_dbus_async_address_resolver_callback(AvahiSAddressResolver *r, AvahiI reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; diff --git a/avahi-daemon/dbus-async-host-name-resolver.c b/avahi-daemon/dbus-async-host-name-resolver.c index 936c3f9..588bc11 100644 --- a/avahi-daemon/dbus-async-host-name-resolver.c +++ b/avahi-daemon/dbus-async-host-name-resolver.c @@ -58,6 +58,11 @@ void avahi_dbus_async_host_name_resolver_callback(AvahiSHostNameResolver *r, Ava reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; diff --git a/avahi-daemon/dbus-async-service-resolver.c b/avahi-daemon/dbus-async-service-resolver.c index 023543d..19da6ff 100644 --- a/avahi-daemon/dbus-async-service-resolver.c +++ b/avahi-daemon/dbus-async-service-resolver.c @@ -73,6 +73,11 @@ void avahi_dbus_async_service_resolver_callback( reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; diff --git a/avahi-daemon/dbus-domain-browser.c b/avahi-daemon/dbus-domain-browser.c index 80155b2..47a5f42 100644 --- a/avahi-daemon/dbus-domain-browser.c +++ b/avahi-daemon/dbus-domain-browser.c @@ -109,6 +109,11 @@ void avahi_dbus_domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex int m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { assert(domain); dbus_message_append_args( diff --git a/avahi-daemon/dbus-entry-group.c b/avahi-daemon/dbus-entry-group.c index 45c9be3..0b86436 100644 --- a/avahi-daemon/dbus-entry-group.c +++ b/avahi-daemon/dbus-entry-group.c @@ -63,6 +63,11 @@ void avahi_dbus_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiE m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged"); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + t = (int32_t) state; if (state == AVAHI_ENTRY_GROUP_FAILURE) e = avahi_error_number_to_dbus(avahi_server_errno(s)); diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index 937e64d..542b5ca 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -1017,6 +1017,12 @@ void dbus_protocol_server_state_changed(AvahiServerState state) { return; m = dbus_message_new_signal(AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "StateChanged"); + + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + t = (int32_t) state; if (state == AVAHI_SERVER_COLLISION) diff --git a/avahi-daemon/dbus-record-browser.c b/avahi-daemon/dbus-record-browser.c index 57be6e8..f4cd217 100644 --- a/avahi-daemon/dbus-record-browser.c +++ b/avahi-daemon/dbus-record-browser.c @@ -116,6 +116,11 @@ void avahi_dbus_record_browser_callback( m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { uint8_t rdata[0xFFFF]; size_t size; diff --git a/avahi-daemon/dbus-service-browser.c b/avahi-daemon/dbus-service-browser.c index f945e65..104165b 100644 --- a/avahi-daemon/dbus-service-browser.c +++ b/avahi-daemon/dbus-service-browser.c @@ -105,6 +105,11 @@ void avahi_dbus_service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex i m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW) { /* Patch in AVAHI_LOOKUP_RESULT_OUR_OWN */ diff --git a/avahi-daemon/dbus-service-type-browser.c b/avahi-daemon/dbus-service-type-browser.c index ce4787f..03cc091 100644 --- a/avahi-daemon/dbus-service-type-browser.c +++ b/avahi-daemon/dbus-service-type-browser.c @@ -109,6 +109,11 @@ void avahi_dbus_service_type_browser_callback(AvahiSServiceTypeBrowser *b, Avahi m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { assert(type); assert(domain); diff --git a/avahi-daemon/dbus-sync-address-resolver.c b/avahi-daemon/dbus-sync-address-resolver.c index 5cad5a7..9845420 100644 --- a/avahi-daemon/dbus-sync-address-resolver.c +++ b/avahi-daemon/dbus-sync-address-resolver.c @@ -68,6 +68,12 @@ void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIf u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -85,6 +91,6 @@ void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIf avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_address_resolver_free(i); } - diff --git a/avahi-daemon/dbus-sync-host-name-resolver.c b/avahi-daemon/dbus-sync-host-name-resolver.c index febbd25..e511327 100644 --- a/avahi-daemon/dbus-sync-host-name-resolver.c +++ b/avahi-daemon/dbus-sync-host-name-resolver.c @@ -68,6 +68,12 @@ void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, Avah u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -85,6 +91,6 @@ void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, Avah avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_host_name_resolver_free(i); } - diff --git a/avahi-daemon/dbus-sync-service-resolver.c b/avahi-daemon/dbus-sync-service-resolver.c index 6d39d4e..ed7276a 100644 --- a/avahi-daemon/dbus-sync-service-resolver.c +++ b/avahi-daemon/dbus-sync-service-resolver.c @@ -90,12 +90,18 @@ void avahi_dbus_sync_service_resolver_callback( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; if (a) - i_aprotocol = (int32_t) a->proto; - else - i_aprotocol = AVAHI_PROTO_UNSPEC; + i_aprotocol = (int32_t) a->proto; + else + i_aprotocol = AVAHI_PROTO_UNSPEC; u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -124,5 +130,6 @@ void avahi_dbus_sync_service_resolver_callback( avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_service_resolver_free(i); } diff --git a/avahi-daemon/dbus-util.c b/avahi-daemon/dbus-util.c index dc28303..2983b29 100644 --- a/avahi-daemon/dbus-util.c +++ b/avahi-daemon/dbus-util.c @@ -52,6 +52,12 @@ DBusHandlerResult avahi_dbus_respond_error(DBusConnection *c, DBusMessage *m, in text = avahi_strerror(error); reply = dbus_message_new_error(m, avahi_error_number_to_dbus(error), text); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -64,6 +70,12 @@ DBusHandlerResult avahi_dbus_respond_string(DBusConnection *c, DBusMessage *m, c DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -75,6 +87,12 @@ DBusHandlerResult avahi_dbus_respond_int32(DBusConnection *c, DBusMessage *m, in DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -86,6 +104,12 @@ DBusHandlerResult avahi_dbus_respond_uint32(DBusConnection *c, DBusMessage *m, u DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &u, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -97,6 +121,12 @@ DBusHandlerResult avahi_dbus_respond_boolean(DBusConnection *c, DBusMessage *m, DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -108,6 +138,12 @@ DBusHandlerResult avahi_dbus_respond_ok(DBusConnection *c, DBusMessage *m) { DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -118,6 +154,12 @@ DBusHandlerResult avahi_dbus_respond_path(DBusConnection *c, DBusMessage *m, con DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply);