Always assert that BUS_CONNECTION_DATA() returns non-NULL

Every DBusConnection in the dbus-daemon should have been through
bus_connections_setup_connection(), so we can assert that the
BusConnectionData has been attached to it. Having this assertion
is enough to hint to Coverity that it does not need to worry about
whether this pointer might be NULL.

In regression tests, we do work with a few fake client-side
DBusConnection instances in the same process; but it would be a
serious bug if we mixed those up with the ones processed by
dbus-daemon's real code, so the assertion is still valid.

This patch has been inspired by (and fixes) the following coverity scan issues:
CID 54846: Dereference null return value (NULL_RETURNS).
CID 54854: Dereference null return value (NULL_RETURNS).

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
[smcv: fixed -Wdeclaration-after-statement; more informative commit message]
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
This commit is contained in:
Ralf Habacker 2015-04-14 23:17:40 +02:00 committed by Simon McVittie
parent 26a3c0dc5b
commit d5e7e2794e

View file

@ -35,6 +35,7 @@
#include <dbus/dbus-hash.h>
#include <dbus/dbus-timeout.h>
#include <dbus/dbus-connection-internal.h>
#include <dbus/dbus-internals.h>
/* Trim executed commands to this length; we want to keep logs readable */
#define MAX_LOG_COMMAND_LEN 50
@ -134,6 +135,7 @@ connection_get_loop (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
return bus_context_get_loop (d->connections->context);
}
@ -638,9 +640,12 @@ static void
check_pending_fds_cb (DBusConnection *connection)
{
BusConnectionData *d = BUS_CONNECTION_DATA (connection);
int n_pending_unix_fds_old = d->n_pending_unix_fds;
int n_pending_unix_fds_old;
int n_pending_unix_fds_new;
_dbus_assert(d != NULL);
n_pending_unix_fds_old = d->n_pending_unix_fds;
n_pending_unix_fds_new = _dbus_connection_get_pending_fds_count (connection);
_dbus_verbose ("Pending fds count changed on connection %p: %d -> %d\n",
@ -1012,6 +1017,7 @@ bus_connection_get_loginfo (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
if (!bus_connection_is_active (connection))
return "inactive";
@ -1248,8 +1254,9 @@ bus_connection_is_active (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
return d != NULL && d->name != NULL;
return d->name != NULL;
}
dbus_bool_t
@ -2649,6 +2656,8 @@ bus_connection_get_peak_match_rules (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
return d->peak_match_rules;
}
@ -2658,6 +2667,8 @@ bus_connection_get_peak_bus_names (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
return d->peak_bus_names;
}
#endif /* DBUS_ENABLE_STATS */
@ -2668,8 +2679,9 @@ bus_connection_is_monitor (DBusConnection *connection)
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
_dbus_assert(d != NULL);
return d != NULL && d->link_in_monitors != NULL;
return d->link_in_monitors != NULL;
}
static dbus_bool_t