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



commit bb143a839c317daf0aae57666a21cf3b90c41465
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 54be6cb..8d33be7 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -555,30 +555,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]