]> git.meshlink.io Git - catta/commitdiff
daemon: add some minimal OOM checking against D-Bus
authorLennart Poettering <lennart@poettering.net>
Fri, 25 Jun 2010 21:12:57 +0000 (23:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 25 Jun 2010 21:12:57 +0000 (23:12 +0200)
13 files changed:
avahi-daemon/dbus-async-address-resolver.c
avahi-daemon/dbus-async-host-name-resolver.c
avahi-daemon/dbus-async-service-resolver.c
avahi-daemon/dbus-domain-browser.c
avahi-daemon/dbus-entry-group.c
avahi-daemon/dbus-protocol.c
avahi-daemon/dbus-record-browser.c
avahi-daemon/dbus-service-browser.c
avahi-daemon/dbus-service-type-browser.c
avahi-daemon/dbus-sync-address-resolver.c
avahi-daemon/dbus-sync-host-name-resolver.c
avahi-daemon/dbus-sync-service-resolver.c
avahi-daemon/dbus-util.c

index dcb15e73f0bd8e65d444616b2cfd959b87529c39..5be08c29ae30ed60b65c119b8d148f2371c21f16 100644 (file)
@@ -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;
index 936c3f97e30698997160e3a244b530ab9925fa33..588bc11d8accce7bc06642eb9a933fcda4a893ea 100644 (file)
@@ -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;
index 023543d87ecec40404f9c6f981f2596cb22de276..19da6ffe27dc88354798bda20166d4806509f9fb 100644 (file)
@@ -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;
index 80155b28ab93b0bc185bd3dc0b9f4f20948151f2..47a5f4245115bf6ec1f0e42ab19069340257484f 100644 (file)
@@ -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(
index 45c9be3d7625df12e33a9cf1b81aeebae6d90531..0b8643684751057d187d294e5c7dc30e7932dedc 100644 (file)
@@ -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));
index 937e64df9f5e0920a79210e932cc76d02db3838d..542b5ca411c952f618dd9e45083ad5c5d9608fc5 100644 (file)
@@ -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)
index 57be6e8d2961d7a26ea19dfb8a63e55cb80edfd5..f4cd2179cccb0606879e79aa4e07a840b46cd6aa 100644 (file)
@@ -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;
index f945e65dff6048eaddb9602f1801006db37c4869..104165b83e71fadd02ed5adecd6b6997339f4395 100644 (file)
@@ -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 */
 
index ce4787f3f8a0d40574e9ccee5a8ed2ad76058f71..03cc091084e9c2a9b8e3d33900ddd239f986d3fa 100644 (file)
@@ -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);
index 5cad5a7d3a33727f007703138ad26a2403f87425..9845420c9b730cd9f1405010edc4720c289ea372 100644 (file)
@@ -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);
 }
-
index febbd25ee5f5d9f225667fe2c8a76ee010ff2fd2..e5113276d483ff45d698fd085a3392d99f6783f1 100644 (file)
@@ -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);
 }
-
index 6d39d4e9901192284e2359f1e8b1e31374aace99..ed7276afd4734ecbe56e0cb8f33b95dfff991752 100644 (file)
@@ -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);
 }
index dc28303e6fd49c145237b60e2e7d012f5d013e84..2983b299b0a52fe667c1bdc997850463dcfb7ff4 100644 (file)
@@ -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);