[gnome-online-accounts/gnome-3-22] facebook: Avoid CRITICALs if get_identity_sync can't parse the response



commit 1e76e2d38fbbba718cee0003c55f32da9ae7c2c8
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Aug 1 16:51:49 2017 +0200

    facebook: Avoid CRITICALs if get_identity_sync can't parse the response
    
    The json_object_get_string_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/goafacebookprovider.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index 471d7a9..7adc774 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -229,8 +229,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,
@@ -239,19 +238,18 @@ get_identity_sync (GoaOAuth2Provider  *oauth2_provider,
                    _("Could not parse response"));
       goto out;
     }
-  presentation_identity = g_strdup (json_object_get_string_member (json_object, "email"));
-  if (presentation_identity == NULL)
+
+  id = g_strdup (json_object_get_string_member (json_object, "id"));
+
+  if (json_object_has_member (json_object, "email"))
+    presentation_identity = g_strdup (json_object_get_string_member (json_object, "email"));
+  else if (json_object_has_member (json_object, "username"))
+    presentation_identity = g_strdup (json_object_get_string_member (json_object, "username"));
+  else
     {
-      presentation_identity = g_strdup (json_object_get_string_member (json_object, "username"));
-      if (presentation_identity == NULL)
-        {
-          g_warning ("Did not find email or username in JSON data");
-          g_set_error (error,
-                       GOA_ERROR,
-                       GOA_ERROR_FAILED,
-                       _("Could not parse response"));
-          goto out;
-        }
+      g_warning ("Did not find email or username in JSON data");
+      g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Could not parse response"));
+      goto out;
     }
 
   ret = id;


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