[prevent][33973] Fix for unchecked return value
[platform/upstream/at-spi2-core.git] / atspi / atspi-misc.c
index c6b4581..e102c9b 100644 (file)
@@ -179,6 +179,7 @@ handle_get_bus_address (DBusPendingCall *pending, void *user_data)
   DBusMessage *message;
   const char *address;
   DBusPendingCall *new_pending;
+  dbus_bool_t result;
 
   if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
   {
@@ -215,9 +216,9 @@ handle_get_bus_address (DBusPendingCall *pending, void *user_data)
                                           "/org/a11y/atspi/cache",
                                           atspi_interface_cache, "GetItems");
 
-  dbus_connection_send_with_reply (app->bus, message, &new_pending, 2000);
+  result = dbus_connection_send_with_reply (app->bus, message, &new_pending, 2000);
   dbus_message_unref (message);
-  if (!new_pending)
+  if (!result || !new_pending)
     return;
   dbus_pending_call_set_notify (new_pending, handle_get_items, app, NULL);
 }
@@ -229,6 +230,7 @@ get_application (const char *bus_name)
   char *bus_name_dup;
   DBusMessage *message;
   DBusPendingCall *pending = NULL;
+  dbus_bool_t result;
 
   if (!app_hash)
   {
@@ -249,9 +251,9 @@ get_application (const char *bus_name)
   message = dbus_message_new_method_call (bus_name, atspi_path_root,
                                           atspi_interface_application, "GetApplicationBusAddress");
 
-  dbus_connection_send_with_reply (app->bus, message, &pending, 2000);
+  result = dbus_connection_send_with_reply (app->bus, message, &pending, 2000);
   dbus_message_unref (message);
-  if (!pending)
+  if (!result || !pending)
   {
     g_hash_table_remove (app_hash, bus_name_dup);
     return NULL;
@@ -260,7 +262,7 @@ get_application (const char *bus_name)
   return app;
 }
 
-static AtspiAccessible *
+AtspiAccessible *
 ref_accessible (const char *app_name, const char *path)
 {
   AtspiApplication *app;
@@ -598,54 +600,31 @@ _atspi_ref_accessible (const char *app, const char *path)
   return ref_accessible (app, path);
 }
 
-static AtspiAccessible *
-_atspi_dbus_return_accessible_and_recurse_info_from_message_impl (DBusMessage *message, unsigned char *recurse)
+AtspiAccessible *
+_atspi_dbus_return_accessible_from_message (DBusMessage *message)
 {
   DBusMessageIter iter;
   AtspiAccessible *retval = NULL;
   const char *signature;
-  const char *expected_signature = recurse ? "(so)y" : "(so)";
 
-  if (!message) return NULL;
+  if (!message)
+    return NULL;
 
   signature = dbus_message_get_signature (message);
-  if (!strcmp (signature, expected_signature))
+  if (!strcmp (signature, "(so)"))
   {
     dbus_message_iter_init (message, &iter);
     retval =  _atspi_dbus_return_accessible_from_iter (&iter);
-    if (recurse) {
-      unsigned char value = 0;
-      dbus_message_iter_get_basic (&iter, &value);
-      dbus_message_iter_next (&iter);
-      *recurse = (value != 0);
-    }
   }
   else
   {
-    g_warning ("AT-SPI: Called _atspi_dbus_return_accessible_from_message with unexpected signature %s", signature);
+    g_warning ("AT-SPI: Called _atspi_dbus_return_accessible_from_message with strange signature %s", signature);
   }
   dbus_message_unref (message);
   return retval;
 }
 
 AtspiAccessible *
-_atspi_dbus_return_accessible_from_message (DBusMessage *message)
-{
-  return _atspi_dbus_return_accessible_and_recurse_info_from_message_impl(message, NULL);
-}
-
-AtspiAccessible *
-_atspi_dbus_return_accessible_and_recurse_info_from_message(DBusMessage *message, unsigned char *recurse)
-{
-  if (recurse == NULL) {
-    g_error("AT-SPI: Called _atspi_dbus_return_accessible_and_recurse_info_from_message with NULL argument recurse");
-    dbus_message_unref (message);
-    return NULL;
-  }
-  return _atspi_dbus_return_accessible_and_recurse_info_from_message_impl(message, recurse);
-}
-
-AtspiAccessible *
 _atspi_dbus_return_accessible_from_iter (DBusMessageIter *iter)
 {
   const char *app_name, *path;
@@ -893,7 +872,8 @@ atspi_init (void)
   bus = atspi_get_a11y_bus ();
   if (!bus)
     return 2;
-  dbus_bus_register (bus, NULL);
+  if (!dbus_bus_register (bus, NULL))
+    return 2;
   atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
   dbus_connection_add_filter (bus, atspi_dbus_filter, NULL, NULL);
   match = g_strdup_printf ("type='signal',interface='%s',member='AddAccessible'", atspi_interface_cache);
@@ -1022,6 +1002,7 @@ check_for_hang (DBusMessage *message, DBusError *error, DBusConnection *bus, con
     DBusMessage *message;
     gchar *bus_name_dup;
     DBusPendingCall *pending = NULL;
+    dbus_bool_t result;
     for (l = hung_processes; l; l = l->next)
       if (!strcmp (l->data, bus_name))
         return;
@@ -1030,9 +1011,9 @@ check_for_hang (DBusMessage *message, DBusError *error, DBusConnection *bus, con
                                             "Ping");
     if (!message)
       return;
-    dbus_connection_send_with_reply (bus, message, &pending, -1);
+    result = dbus_connection_send_with_reply (bus, message, &pending, -1);
     dbus_message_unref (message);
-    if (!pending)
+    if (!result || !pending)
       return;
     bus_name_dup = g_strdup (bus_name);
     hung_processes = g_slist_append (hung_processes, bus_name_dup);
@@ -1129,9 +1110,11 @@ _atspi_dbus_call_partial (gpointer obj,
                           const char *type, ...)
 {
   va_list args;
-
+  DBusMessage * result;
   va_start (args, type);
-  return _atspi_dbus_call_partial_va (obj, interface, method, error, type, args);
+  result =  _atspi_dbus_call_partial_va (obj, interface, method, error, type, args);
+  va_end (args);
+  return result;
 }
 
 
@@ -1172,11 +1155,13 @@ out:
   process_deferred_messages ();
   if (dbus_error_is_set (&err))
   {
-    /* TODO: Set gerror */
+    g_set_error_literal(error, ATSPI_ERROR, ATSPI_ERROR_IPC, err.message);
     dbus_error_free (&err);
+    if (reply)
+      dbus_message_unref(reply);
+    return NULL;
   }
-
-  if (reply && dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
+  else if (reply && dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
   {
     const char *err_str = NULL;
     dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err_str, DBUS_TYPE_INVALID);
@@ -1185,7 +1170,6 @@ out:
     dbus_message_unref (reply);
     return NULL;
   }
-
   return reply;
 }