diff options
| author | John (J5) Palmieri <johnp@redhat.com> | 2006-08-08 23:29:03 +0000 | 
|---|---|---|
| committer | John (J5) Palmieri <johnp@redhat.com> | 2006-08-08 23:29:03 +0000 | 
| commit | 9a3145b9f3cb0d7d570230aaa6193f87e3bea604 (patch) | |
| tree | 1d24b643c7086b8732a68c3a14372482ac472c09 | |
| parent | 1fa8e404a4fd9fc723b0a00be09c3c9fce0cfff3 (diff) | |
These are all patches from Kjartan Maraas <kmaraas at gnome dot org>
with cleanups of bugs found from Coverity reports:
* dbus/dbus-sysdeps-util.c (_dbus_write_pid_file):
  close the file on error to avoid a leak
* bus/expirelist.c (bus_expire_list_test):
  Check for NULL on dbus_new0
* bus/activation.c (update_directory):
  remove dead code
* bus/config-parser.c (merge_service_context_hash, start_selinux_child):
  Fix some leaks
* bus/bus.c (process_config_every_time):
  Fixed a leak
* bus/desktop-file.c (parse_key_value):
  Fixed leak
* bus/selinux.c (bus_selinux_id_table_insert):
  Fixed leak
| -rw-r--r-- | ChangeLog | 26 | ||||
| -rw-r--r-- | bus/activation.c | 2 | ||||
| -rw-r--r-- | bus/bus.c | 11 | ||||
| -rw-r--r-- | bus/config-parser.c | 56 | ||||
| -rw-r--r-- | bus/desktop-file.c | 4 | ||||
| -rw-r--r-- | bus/expirelist.c | 12 | ||||
| -rw-r--r-- | bus/selinux.c | 6 | ||||
| -rw-r--r-- | dbus/dbus-sysdeps-util.c | 2 | 
8 files changed, 96 insertions, 23 deletions
| @@ -1,5 +1,31 @@  2006-08-08  John (J5) Palmieri  <johnp@redhat.com> +	These are all patches from Kjartan Maraas <kmaraas at gnome dot org> +	with cleanups of bugs found from Coverity reports: + +	* dbus/dbus-sysdeps-util.c (_dbus_write_pid_file): +	close the file on error to avoid a leak + +	* bus/expirelist.c (bus_expire_list_test): +	Check for NULL on dbus_new0 + +	* bus/activation.c (update_directory): +	remove dead code + +	* bus/config-parser.c (merge_service_context_hash, start_selinux_child): +	Fix some leaks + +	* bus/bus.c (process_config_every_time): +	Fixed a leak + +	* bus/desktop-file.c (parse_key_value): +	Fixed leak + +	* bus/selinux.c (bus_selinux_id_table_insert): +	Fixed leak + +2006-08-08  John (J5) Palmieri  <johnp@redhat.com> +  	* dbus/dbus-object-tree.c (_dbus_object_subtree_new):  	remove dead code diff --git a/bus/activation.c b/bus/activation.c index 40221938..3d169017 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -633,8 +633,6 @@ update_directory (BusActivation       *activation,    if (iter != NULL)      _dbus_directory_close (iter); -  if (desktop_file) -    bus_desktop_file_free (desktop_file);    _dbus_string_free (&filename);    _dbus_string_free (&full_path); @@ -402,11 +402,13 @@ process_config_every_time (BusContext      *context,  {    DBusString full_address;    DBusList *link; -   +  char *addr; +    dbus_bool_t retval;    _DBUS_ASSERT_ERROR_IS_CLEAR (error); +  addr = NULL;    retval = FALSE;    if (!_dbus_string_init (&full_address)) @@ -427,8 +429,6 @@ process_config_every_time (BusContext      *context,    link = _dbus_list_get_last_link (&context->servers);    while (link != NULL)      { -      char *addr; -              addr = dbus_server_get_address (link->data);        if (addr == NULL)          { @@ -452,6 +452,7 @@ process_config_every_time (BusContext      *context,          }        dbus_free (addr); +      addr = NULL;        link = _dbus_list_get_prev_link (&context->servers, link);      } @@ -489,6 +490,10 @@ process_config_every_time (BusContext      *context,   failed:    _dbus_string_free (&full_address); +   +  if (addr) +    dbus_free (addr) +    return retval;  } diff --git a/bus/config-parser.c b/bus/config-parser.c index ff2927a7..5b923632 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -248,27 +248,42 @@ merge_service_context_hash (DBusHashTable *dest,  			    DBusHashTable *from)  {    DBusHashIter iter; -   +  char *service_copy; +  char *context_copy; + +  service_copy = NULL; +  context_copy = NULL; +    _dbus_hash_iter_init (from, &iter);    while (_dbus_hash_iter_next (&iter))      {        const char *service = _dbus_hash_iter_get_string_key (&iter);        const char *context = _dbus_hash_iter_get_value (&iter); -      char *service_copy; -      char *context_copy;        service_copy = _dbus_strdup (service);        if (service_copy == NULL) -        return FALSE; +        goto fail;        context_copy = _dbus_strdup (context);        if (context_copy == NULL) -        return FALSE; +        goto fail;         if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy)) -	return FALSE; +        goto fail; + +      service_copy = NULL; +      context_copy = NULL;          }    return TRUE; + + fail: +  if (service_copy) +    dbus_free (service_copy); + +  if (context_copy) +    dbus_free (context_copy); + +  return FALSE;  }  static dbus_bool_t @@ -1542,12 +1557,16 @@ start_selinux_child (BusConfigParser   *parser,                       const char       **attribute_values,                       DBusError         *error)  { +  char *own_copy; +  char *context_copy; + +  own_copy = NULL; +  context_copy = NULL; +    if (strcmp (element_name, "associate") == 0)      {        const char *own;        const char *context; -      char *own_copy; -      char *context_copy;        if (!locate_attributes (parser, "associate",                                attribute_names, @@ -1573,18 +1592,15 @@ start_selinux_child (BusConfigParser   *parser,        own_copy = _dbus_strdup (own);        if (own_copy == NULL) -        return FALSE; +        goto oom;        context_copy = _dbus_strdup (context);        if (context_copy == NULL) -        return FALSE; +        goto oom;        if (!_dbus_hash_table_insert_string (parser->service_context_table,  					   own_copy, context_copy)) -        { -          BUS_SET_OOM (error); -          return FALSE; -        } -       +        goto oom; +        return TRUE;      }    else @@ -1594,6 +1610,16 @@ start_selinux_child (BusConfigParser   *parser,                        element_name, "selinux");        return FALSE;      } + + oom: +  if (own_copy) +    dbus_free (own_copy); + +  if (context_copy)   +    dbus_free (context_copy); + +  BUS_SET_OOM (error); +  return FALSE;  }  dbus_bool_t diff --git a/bus/desktop-file.c b/bus/desktop-file.c index fc985122..7a96a44c 100644 --- a/bus/desktop-file.c +++ b/bus/desktop-file.c @@ -525,12 +525,14 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)    line = new_line (parser);    if (line == NULL)      { +      dbus_free (value);        parser_free (parser);        return FALSE;      }    if (!_dbus_string_init (&key))      { +      dbus_free (value);        parser_free (parser);        return FALSE;      } @@ -538,12 +540,14 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)    if (!_dbus_string_copy_len (&parser->data, key_start, key_end - key_start,                                &key, 0))      { +      dbus_free (value);        parser_free (parser);        return FALSE;      }    if (!_dbus_string_steal_data (&key, &tmp))      { +      dbus_free (value);        parser_free (parser);        return FALSE;      } diff --git a/bus/expirelist.c b/bus/expirelist.c index 422f3e40..6fa1c6e1 100644 --- a/bus/expirelist.c +++ b/bus/expirelist.c @@ -248,7 +248,9 @@ bus_expire_list_test (const DBusString *test_data_dir)    long tv_sec_past, tv_usec_past;    TestExpireItem *item;    int next_interval; -   +  dbus_bool_t result = FALSE; + +    loop = _dbus_loop_new ();    _dbus_assert (loop != NULL); @@ -276,6 +278,9 @@ bus_expire_list_test (const DBusString *test_data_dir)    item = dbus_new0 (TestExpireItem, 1); +  if (item == NULL) +    goto oom; +    item->item.added_tv_sec = tv_sec;    item->item.added_tv_usec = tv_usec;    if (!_dbus_list_append (&list->items, item)) @@ -308,7 +313,10 @@ bus_expire_list_test (const DBusString *test_data_dir)    bus_expire_list_free (list);    _dbus_loop_unref (loop); -  return TRUE; +  result = TRUE; + + oom: +  return result;  }  #endif /* DBUS_BUILD_TESTS */ diff --git a/bus/selinux.c b/bus/selinux.c index 5ed7e388..e5f26da2 100644 --- a/bus/selinux.c +++ b/bus/selinux.c @@ -756,7 +756,11 @@ bus_selinux_id_table_insert (DBusHashTable *service_table,    if (avc_context_to_sid ((char *) service_context, &sid) < 0)      {        if (errno == ENOMEM) -        return FALSE; +        { +	  dbus_free (key); +          return FALSE; +	} +        _dbus_warn ("Error getting SID from context \"%s\": %s\n",  		  (char *) service_context,                    _dbus_strerror (errno)); diff --git a/dbus/dbus-sysdeps-util.c b/dbus/dbus-sysdeps-util.c index 72db5d34..bfc87801 100644 --- a/dbus/dbus-sysdeps-util.c +++ b/dbus/dbus-sysdeps-util.c @@ -219,6 +219,8 @@ _dbus_write_pid_file (const DBusString *filename,        dbus_set_error (error, _dbus_error_from_errno (errno),                        "Failed to write to \"%s\": %s", cfilename,                        _dbus_strerror (errno)); +       +      fclose (f);        return FALSE;      } | 
