Bug 79006

Summary: [next] Fix clang warnings
Product: Telepathy Reporter: Guillaume Desmottes <guillaume.desmottes>
Component: tp-glibAssignee: Telepathy bugs list <telepathy-bugs>
Status: RESOLVED FIXED QA Contact: Telepathy bugs list <telepathy-bugs>
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: contact-list: don't crash if 'd' is NULL
tp-fs: fix a potential NULL dereferencing crash
tp-fs: add mising 'break' in switch block
account-request: remove useless 'priv' variable
ensure that values received from callback are not NULL
ensure that class pointers aren't NULL
base-client: fix potential uninitialized variable bug
logger: don't assume @error is not NULL
test-connection-error: don't check errors twice
ensure that values received from callback are not NULL
ensure that values received from callback are not NULL

Description Guillaume Desmottes 2014-05-21 08:47:21 UTC
I wanted to give Tartan a shot to see if he could help us finding potential regressions (like signals removing/renaming) in next. I did not manage to use it but find a bunch of bugs and potential issues by using clang alone.

Some of those patches are less useful than others but couldn't hurt from a safer programming pov.
Comment 1 Guillaume Desmottes 2014-05-21 08:58:38 UTC
Created attachment 99477 [details] [review]
contact-list: don't crash if 'd' is NULL
Comment 2 Guillaume Desmottes 2014-05-21 08:58:50 UTC
Created attachment 99478 [details] [review]
tp-fs: fix a potential NULL dereferencing crash
Comment 3 Guillaume Desmottes 2014-05-21 08:59:04 UTC
Created attachment 99479 [details] [review]
tp-fs: add mising 'break' in switch block
Comment 4 Guillaume Desmottes 2014-05-21 08:59:22 UTC
Created attachment 99480 [details] [review]
account-request: remove useless 'priv' variable
Comment 5 Guillaume Desmottes 2014-05-21 08:59:35 UTC
Created attachment 99481 [details] [review]
ensure that values received from callback are not NULL
Comment 6 Guillaume Desmottes 2014-05-21 08:59:46 UTC
Created attachment 99482 [details] [review]
ensure that class pointers aren't NULL
Comment 7 Guillaume Desmottes 2014-05-21 09:00:09 UTC
Created attachment 99483 [details] [review]
base-client: fix potential uninitialized variable bug
Comment 8 Guillaume Desmottes 2014-05-21 09:00:24 UTC
Created attachment 99484 [details] [review]
logger: don't assume @error is not NULL
Comment 9 Guillaume Desmottes 2014-05-21 09:00:41 UTC
Created attachment 99485 [details] [review]
test-connection-error: don't check errors twice
Comment 10 Guillaume Desmottes 2014-05-21 09:00:57 UTC
Comment on attachment 99483 [details] [review]
base-client: fix potential uninitialized variable bug

>From 6c5f392d9487a94a4fa62c1aaaebdc18794dea9d Mon Sep 17 00:00:00 2001
>From: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
>Date: Wed, 21 May 2014 10:52:49 +0200
>Subject: [PATCH 7/9] base-client: fix potential uninitialized variable bug
>
>https://bugs.freedesktop.org/show_bug.cgi?id=79006
>---
> telepathy-glib/base-client.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c
>index cb717ca..e9040e2 100644
>--- a/telepathy-glib/base-client.c
>+++ b/telepathy-glib/base-client.c
>@@ -2328,7 +2328,7 @@ _tp_base_client_add_request (TpSvcClientInterfaceRequests *iface,
> {
>   TpBaseClient *self = TP_BASE_CLIENT (iface);
>   TpChannelRequest *request;
>-  TpAccount *account;
>+  TpAccount *account = NULL;
>   GError *error = NULL;
>   channel_request_prepare_account_ctx *ctx;
>   GArray *account_features;
>-- 
>1.9.0
>
Comment 11 Guillaume Desmottes 2014-05-21 09:01:27 UTC
(In reply to comment #10)
> Comment on attachment 99483 [details] [review] [review]
> base-client: fix potential uninitialized variable bug
> 
> >From 6c5f392d9487a94a4fa62c1aaaebdc18794dea9d Mon Sep 17 00:00:00 2001
> >From: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
> >Date: Wed, 21 May 2014 10:52:49 +0200
> >Subject: [PATCH 7/9] base-client: fix potential uninitialized variable bug
> >
> >https://bugs.freedesktop.org/show_bug.cgi?id=79006
> >---
> > telepathy-glib/base-client.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c
> >index cb717ca..e9040e2 100644
> >--- a/telepathy-glib/base-client.c
> >+++ b/telepathy-glib/base-client.c
> >@@ -2328,7 +2328,7 @@ _tp_base_client_add_request (TpSvcClientInterfaceRequests *iface,
> > {
> >   TpBaseClient *self = TP_BASE_CLIENT (iface);
> >   TpChannelRequest *request;
> >-  TpAccount *account;
> >+  TpAccount *account = NULL;
> >   GError *error = NULL;
> >   channel_request_prepare_account_ctx *ctx;
> >   GArray *account_features;
> >-- 
> >1.9.0
> >

Ooops, sorry; ignore that quote.
Comment 12 Simon McVittie 2014-05-26 11:07:53 UTC
Comment on attachment 99481 [details] [review]
ensure that values received from callback are not NULL

Review of attachment 99481 [details] [review]:
-----------------------------------------------------------------

::: telepathy-glib/account.c
@@ +3313,4 @@
>  {
>    GTask *task = user_data;
>  
> +  g_return_if_fail (out_Value);

This shouldn't be asserted until after @error has been checked?

::: telepathy-glib/base-room-config.c
@@ +759,4 @@
>    static TpDBusPropertiesMixinIfaceInfo *iface_info = NULL;
>    TpDBusPropertiesMixinPropInfo *prop_info;
>  
> +  g_return_val_if_fail (value != NULL, FALSE);

(unreviewed, I'll need to see more context)

::: telepathy-glib/connection.c
@@ +515,4 @@
>    TpConnection *self = (TpConnection *) proxy;
>    GSimpleAsyncResult *result;
>  
> +  g_return_if_fail (value != NULL);

Should not be asserted until @error has been checked

::: telepathy-glib/debug-client.c
@@ +268,4 @@
>  {
>    TpDebugClient *self = TP_DEBUG_CLIENT (proxy);
>  
> +  g_return_if_fail (value != NULL);

Likewise
Comment 13 Simon McVittie 2014-05-26 11:09:02 UTC
Comment on attachment 99479 [details] [review]
tp-fs: add mising 'break' in switch block

Review of attachment 99479 [details] [review]:
-----------------------------------------------------------------

This one seems worth fixing in stable too
Comment 14 Simon McVittie 2014-05-26 11:09:44 UTC
Comment on attachment 99478 [details] [review]
tp-fs: fix a potential NULL dereferencing crash

Review of attachment 99478 [details] [review]:
-----------------------------------------------------------------

::: telepathy-farstream/call-stream.c
@@ +331,5 @@
>        tf_call_stream_fail (self,
>            TP_CALL_STATE_CHANGE_REASON_INTERNAL_ERROR,
>            TP_ERROR_STR_MEDIA_STREAMING_ERROR,
> +          "Error setting the remote candidates: %s",
> +          error != NULL ? error->message : "invalid transport type");

This usually indicates that GError is being used incorrectly; I'll have to look at more context.
Comment 15 Simon McVittie 2014-05-26 11:10:06 UTC
Comment on attachment 99483 [details] [review]
base-client: fix potential uninitialized variable bug

Review of attachment 99483 [details] [review]:
-----------------------------------------------------------------

++, worth fixing in stable
Comment 16 Simon McVittie 2014-05-26 11:11:20 UTC
Comment on attachment 99484 [details] [review]
logger: don't assume @error is not NULL

Review of attachment 99484 [details] [review]:
-----------------------------------------------------------------

::: telepathy-logger/log-store-xml.c
@@ +451,5 @@
>    bus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
>    if (bus_connection == NULL)
>      {
> +      DEBUG ("Error acquiring bus connection: %s",
> +          error != NULL ? (*error)->message : "");

I'd prefer "(no GError available)" over "" as the fallback.
Comment 17 Simon McVittie 2014-05-26 11:12:31 UTC
All OK except where noted. Please apply to stable and master where noted. For changes not suitable for stable, please apply to master if it's easy to do so.
Comment 18 Guillaume Desmottes 2014-05-26 11:36:23 UTC
Created attachment 99859 [details] [review]
ensure that values received from callback are not NULL

fixed.
Comment 19 Guillaume Desmottes 2014-05-26 11:39:29 UTC
(In reply to comment #13)
> Comment on attachment 99479 [details] [review] [review]
> tp-fs: add mising 'break' in switch block
> 
> Review of attachment 99479 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> This one seems worth fixing in stable too

Fixed in tp-fs master as well (we didn't branch for 0.6).
Comment 20 Guillaume Desmottes 2014-05-26 11:45:15 UTC
(In reply to comment #14)
> Comment on attachment 99478 [details] [review] [review]
> tp-fs: fix a potential NULL dereferencing crash
> 
> Review of attachment 99478 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: telepathy-farstream/call-stream.c
> @@ +331,5 @@
> >        tf_call_stream_fail (self,
> >            TP_CALL_STATE_CHANGE_REASON_INTERNAL_ERROR,
> >            TP_ERROR_STR_MEDIA_STREAMING_ERROR,
> > +          "Error setting the remote candidates: %s",
> > +          error != NULL ? error->message : "invalid transport type");
> 
> This usually indicates that GError is being used incorrectly; I'll have to
> look at more context.

The only case where it can happen, assuming the called functions properly set the error if they failed, is the default switch case. We can just g_return_if_reached() if you prefer.

static void
_tf_call_stream_push_remote_candidates (TfCallStream *self,
    GList *fscandidates)
{
  gboolean ret;
  GError *error = NULL;

  switch (self->transport_type)
    {
    case TP_STREAM_TRANSPORT_TYPE_RAW_UDP:
    case TP_STREAM_TRANSPORT_TYPE_SHM:
    case TP_STREAM_TRANSPORT_TYPE_MULTICAST:
      ret = fs_stream_force_remote_candidates (self->fsstream,
          fscandidates, &error);
      break;
    case TP_STREAM_TRANSPORT_TYPE_ICE:
    case TP_STREAM_TRANSPORT_TYPE_GTALK_P2P:
    case TP_STREAM_TRANSPORT_TYPE_WLM_2009:
      ret = fs_stream_add_remote_candidates (self->fsstream, fscandidates,
          &error);
      break;
    default:
      ret = FALSE;
    }

  if (!ret)
    {
      tf_call_stream_fail (self,
          TP_CALL_STATE_CHANGE_REASON_INTERNAL_ERROR,
          TP_ERROR_STR_MEDIA_STREAMING_ERROR,
          "Error setting the remote candidates: %s",
          error != NULL ? error->message : "invalid transport type");
      g_clear_error (&error);
    }
Comment 21 Guillaume Desmottes 2014-05-26 11:48:20 UTC
Created attachment 99861 [details] [review]
ensure that values received from callback are not NULL
Comment 22 Guillaume Desmottes 2014-05-26 11:48:41 UTC
(In reply to comment #15)
> Comment on attachment 99483 [details] [review] [review]
> base-client: fix potential uninitialized variable bug
> 
> Review of attachment 99483 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ++, worth fixing in stable

Pushed to 0.24
Comment 23 Guillaume Desmottes 2014-05-26 12:16:28 UTC
All merged to master/next but:
- tp-fs: fix a potential NULL dereferencing crash
- ensure that values received from callback are not NULL
Comment 24 Simon McVittie 2014-05-26 15:01:00 UTC
Comment on attachment 99478 [details] [review]
tp-fs: fix a potential NULL dereferencing crash

Review of attachment 99478 [details] [review]:
-----------------------------------------------------------------

With the additional context that you quoted: yes this is correct (if a bit weird), please merge.
Comment 25 Simon McVittie 2014-05-26 15:04:31 UTC
Comment on attachment 99861 [details] [review]
ensure that values received from callback are not NULL

Review of attachment 99861 [details] [review]:
-----------------------------------------------------------------

This one looks fine now.

::: telepathy-glib/account.c
@@ +3312,5 @@
>      GObject *weak_object)
>  {
>    GTask *task = user_data;
>  
> +  g_return_if_fail (error != NULL || value != NULL);

Much better

::: telepathy-glib/base-room-config.c
@@ +759,4 @@
>    static TpDBusPropertiesMixinIfaceInfo *iface_info = NULL;
>    TpDBusPropertiesMixinPropInfo *prop_info;
>  
> +  g_return_val_if_fail (value != NULL, FALSE);

I've looked at the context now, and yes it's correct
Comment 26 Guillaume Desmottes 2014-05-27 08:24:33 UTC
All merged; thanks!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.