From: Ralf Habacker Date: Tue, 14 Apr 2015 21:17:40 +0000 (+0200) Subject: Always assert that BUS_CONNECTION_DATA() returns non-NULL X-Git-Tag: dbus-1.9.16~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5e7e2794ecc213f5e3332a3bc36aa1708bdb637;p=thirdparty%2Fdbus.git 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 [smcv: fixed -Wdeclaration-after-statement; more informative commit message] Reviewed-by: Ralf Habacker --- diff --git a/bus/connection.c b/bus/connection.c index 690f3a5db..95e20a6e1 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -35,6 +35,7 @@ #include #include #include +#include /* 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