[gnome-online-accounts/wip/rishi/facebook: 7/14] live: Avoid CRITICALs if get_identity_sync can't parse response



commit d9d9e8ae6cd51cde9c0601fb449c6b63429d1d8c
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Aug 2 18:27:19 2017 +0200

    live: Avoid CRITICALs if get_identity_sync 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/goawindowsliveprovider.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index 5ee7112..109abb2 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -179,8 +179,7 @@ get_identity_sync (GoaOAuth2Provider  *oauth2_provider,
     }
 
   json_object = json_node_get_object (json_parser_get_root (parser));
-  id = g_strdup (json_object_get_string_member (json_object, "id"));
-  if (id == NULL)
+  if (!json_object_has_member (json_object, "id"))
     {
       g_warning ("Did not find id in JSON data");
       g_set_error (error,
@@ -189,10 +188,20 @@ get_identity_sync (GoaOAuth2Provider  *oauth2_provider,
                    _("Could not parse response"));
       goto out;
     }
+  if (!json_object_has_member (json_object, "emails"))
+    {
+      g_warning ("Did not find emails in JSON data");
+      g_set_error (error,
+                   GOA_ERROR,
+                   GOA_ERROR_FAILED,
+                   _("Could not parse response"));
+      goto out;
+    }
+
+  id = g_strdup (json_object_get_string_member (json_object, "id"));
 
   json_object = json_object_get_object_member (json_object, "emails");
-  presentation_identity = g_strdup (json_object_get_string_member (json_object, "account"));
-  if (presentation_identity == NULL)
+  if (!json_object_has_member (json_object, "account"))
     {
       g_warning ("Did not find emails.account in JSON data");
       g_set_error (error,
@@ -202,6 +211,8 @@ get_identity_sync (GoaOAuth2Provider  *oauth2_provider,
       goto out;
     }
 
+  presentation_identity = g_strdup (json_object_get_string_member (json_object, "account"));
+
   ret = id;
   id = NULL;
   if (out_presentation_identity != NULL)


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