[gnome-online-accounts] lastfm: Avoid CRITICALs if check_cb can't parse response



commit fd838c96ab8bf470c7a7d7d3e428602414a5f5d4
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Aug 3 16:56:55 2017 +0200

    lastfm: Avoid CRITICALs if check_cb can't parse response
    
    The json_object_get_*_member API expects the member to be present.
    Therefore, we should not use its return value to determine its
    availability. Otherwise it will lead to:
      Json-CRITICAL **: json_object_get_string_member: assertion
        'node != NULL' failed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785726

 src/goabackend/goalastfmprovider.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/goabackend/goalastfmprovider.c b/src/goabackend/goalastfmprovider.c
index 98b979c..92395d9 100644
--- a/src/goabackend/goalastfmprovider.c
+++ b/src/goabackend/goalastfmprovider.c
@@ -519,27 +519,27 @@ check_cb (RestProxyCall *call,
     }
 
   json_obj = json_node_get_object (json_parser_get_root (parser));
-  session = json_object_get_member (json_obj, "session");
-  if (session == NULL)
+  if (!json_object_has_member (json_obj, "session"))
     {
       g_set_error (&data->error, GOA_ERROR, GOA_ERROR_FAILED, _("Authentication failed"));
       goto out;
     }
-  session_obj = json_node_get_object (session);
 
-  if (json_object_get_string_member (session_obj, "name") == NULL)
+  session = json_object_get_member (json_obj, "session");
+  session_obj = json_node_get_object (session);
+  if (!json_object_has_member (session_obj, "name"))
     {
       g_set_error (&data->error, GOA_ERROR, GOA_ERROR_FAILED, _("Could not parse response"));
       goto out;
     }
-
-  data->access_token = g_strdup (json_object_get_string_member (session_obj, "key"));
-  if (data->access_token == NULL)
+  if (!json_object_has_member (session_obj, "key"))
     {
       g_set_error (&data->error, GOA_ERROR, GOA_ERROR_FAILED, _("Could not parse response"));
       goto out;
     }
 
+  data->access_token = g_strdup (json_object_get_string_member (session_obj, "key"));
+
  out:
   g_main_loop_quit (data->loop);
   gtk_widget_set_sensitive (data->connect_button, TRUE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]