[epiphany/wip/google-safe-browsing: 7/13] gsb-service: Matches array can miss from fullHashes:find response



commit 65f5c842d9dd3ab6c56e03013e618ab1cddb4649
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Tue Sep 26 15:47:45 2017 +0300

    gsb-service: Matches array can miss from fullHashes:find response

 lib/safe-browsing/ephy-gsb-service.c |   49 ++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 23 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index b92f737..953a8b3 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -556,30 +556,33 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
 
   body_node = json_from_string (msg->response_body->data, NULL);
   body_obj = json_node_get_object (body_node);
-  matches = json_object_get_array_member (body_obj, "matches");
 
-  /* Update full hashes in database. */
-  for (guint i = 0; i < json_array_get_length (matches); i++) {
-    EphyGSBThreatList *list;
-    JsonObject *match = json_array_get_object_element (matches, i);
-    const char *threat_type = json_object_get_string_member (match, "threatType");
-    const char *platform_type = json_object_get_string_member (match, "platformType");
-    const char *threat_entry_type = json_object_get_string_member (match, "threatEntryType");
-    JsonObject *threat = json_object_get_object_member (match, "threat");
-    const char *hash_b64 = json_object_get_string_member (threat, "hash");
-    const char *positive_duration;
-    guint8 *hash;
-    gsize length;
-
-    list = ephy_gsb_threat_list_new (threat_type, platform_type, threat_entry_type, NULL);
-    hash = g_base64_decode (hash_b64, &length);
-    positive_duration = json_object_get_string_member (match, "cacheDuration");
-    sscanf (positive_duration, "%lfs", &duration);
-
-    ephy_gsb_storage_insert_full_hash (self->storage, list, hash, floor (duration));
-
-    g_free (hash);
-    ephy_gsb_threat_list_free (list);
+  if (json_object_has_non_null_array_member (body_obj, "matches")) {
+    matches = json_object_get_array_member (body_obj, "matches");
+
+    /* Update full hashes in database. */
+    for (guint i = 0; i < json_array_get_length (matches); i++) {
+      EphyGSBThreatList *list;
+      JsonObject *match = json_array_get_object_element (matches, i);
+      const char *threat_type = json_object_get_string_member (match, "threatType");
+      const char *platform_type = json_object_get_string_member (match, "platformType");
+      const char *threat_entry_type = json_object_get_string_member (match, "threatEntryType");
+      JsonObject *threat = json_object_get_object_member (match, "threat");
+      const char *hash_b64 = json_object_get_string_member (threat, "hash");
+      const char *positive_duration;
+      guint8 *hash;
+      gsize length;
+
+      list = ephy_gsb_threat_list_new (threat_type, platform_type, threat_entry_type, NULL);
+      hash = g_base64_decode (hash_b64, &length);
+      positive_duration = json_object_get_string_member (match, "cacheDuration");
+      sscanf (positive_duration, "%lfs", &duration);
+
+      ephy_gsb_storage_insert_full_hash (self->storage, list, hash, floor (duration));
+
+      g_free (hash);
+      ephy_gsb_threat_list_free (list);
+    }
   }
 
   /* Update negative cache duration. */


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