edbus: Fix array access of shared_connection
authorDaniel Willmann <d.willmann@samsung.com>
Mon, 18 Feb 2013 12:10:22 +0000 (12:10 +0000)
committerDaniel Willmann <d.willmann@samsung.com>
Mon, 18 Feb 2013 12:22:45 +0000 (12:22 +0000)
type is an enum which can be 0. Make sure that it isn't before accessing
shared_connections[type - 1]
Found with klocwork

Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
src/lib/edbus/edbus_core.c

index 7d5c660..2fb5c6d 100644 (file)
@@ -73,7 +73,9 @@ EAPI const EDBus_Version * edbus_version = &_version;
 static int _edbus_init_count = 0;
 int _edbus_log_dom = -1;
 
-static EDBus_Connection *shared_connections[3];
+/* We don't save EDBUS_CONNECTION_TYPE_UNKNOWN in here so we need room for 
+ * last - 1 elements */
+static EDBus_Connection *shared_connections[EDBUS_CONNECTION_TYPE_LAST - 1];
 
 static void _edbus_connection_event_callback_call(EDBus_Connection *conn, EDBus_Connection_Event_Type type, const void *event_info);
 static void _edbus_connection_context_event_cb_del(EDBus_Connection_Context_Event *ce, EDBus_Connection_Context_Event_Cb *ctx);
@@ -985,6 +987,10 @@ edbus_connection_get(EDBus_Connection_Type type)
    EDBus_Connection *conn;
 
    DBG("Getting connection with type %d", type);
+
+   if (!type)
+     return NULL;
+
    conn = shared_connections[type - 1];
    if (conn)
      {
@@ -1118,7 +1124,7 @@ _edbus_connection_unref(EDBus_Connection *conn)
    edbus_data_del_all(&conn->data);
 
    if (conn->idler) ecore_idler_del(conn->idler);
-   if (shared_connections[conn->type - 1] == conn)
+   if (conn->type && (shared_connections[conn->type - 1] == conn))
      shared_connections[conn->type - 1] = NULL;
 
    free(conn);