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



commit 91119bf36e47f865a72fb3c36b21a78fff3ac86b
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 23e0c1a..24b2107 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -553,30 +553,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]