From 82242a8c2e74c788e5cae9085c64d1ed31e3078b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Forysiuk?= Date: Wed, 5 Sep 2012 23:58:21 +0200 Subject: [PATCH] Adblock: check if file contains any metadata first --- extensions/adblock.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 2dbd4091..91855dab 100644 --- a/extensions/adblock.c +++ b/extensions/adblock.c @@ -1539,14 +1539,16 @@ static gboolean adblock_file_is_up_to_date (gchar* path) { FILE* file; - guint days_to_expire = 0; - gchar* timestamp = NULL; gchar line[2000]; /* Check a chunk of header for update info */ if ((file = g_fopen (path, "r"))) { + guint days_to_expire = 0; + gchar* timestamp = NULL; guint i; + gboolean found_meta = FALSE; + for (i = 0; i <= 10; i++) { fgets (line, 2000, file); @@ -1555,6 +1557,7 @@ adblock_file_is_up_to_date (gchar* path) gchar** parts = g_strsplit (line, " ", 4); days_to_expire = atoi (parts[2]); g_strfreev (parts); + found_meta = TRUE; } if (strncmp ("! This list expires after", line, 25) == 0) { @@ -1566,6 +1569,7 @@ adblock_file_is_up_to_date (gchar* path) days_to_expire = (atoi (parts[5])) / 24; g_strfreev (parts); + found_meta = TRUE; } if (strncmp ("! Last modified", line, 15) == 0 @@ -1575,9 +1579,16 @@ adblock_file_is_up_to_date (gchar* path) timestamp = g_strdup (parts[1] + 1); g_strchomp (timestamp); g_strfreev (parts); + found_meta = TRUE; } } + if (!found_meta) + { + g_print ("Adblock: no metadata found in %s (broken download?)\n", path); + return FALSE; + } + if (days_to_expire && timestamp != NULL) { guint days_elapsed = 0; -- 2.39.5