[epiphany] adblock: Avoid underflow in timestamp checks



commit 7ed29e8314ae9b0f2eb81066c429cc60cd0c9605
Author: Adrian Perez de Castro <aperez igalia com>
Date:   Fri Sep 6 13:03:17 2019 +0300

    adblock: Avoid underflow in timestamp checks
    
    Since the change to use signed times, the calculation inside
    filter_info_needs_updating_from_source() could underflow, which
    would result in (wrongly) considering that rule sets would never
    need downloading.
    
    This fixes the the calculations to avoid underflows.

 embed/ephy-filters-manager.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/embed/ephy-filters-manager.c b/embed/ephy-filters-manager.c
index dcc57ca23..95136cbdc 100644
--- a/embed/ephy-filters-manager.c
+++ b/embed/ephy-filters-manager.c
@@ -399,8 +399,18 @@ filter_info_needs_updating_from_source (const FilterInfo *self)
     return g_date_time_to_unix (modification_time) > self->last_update;
   }
 
-  /* For remote filters, check the time elapsed since the last fetch. */
-  return (self->manager->update_time - self->last_update) >= ADBLOCK_FILTER_UPDATE_FREQUENCY;
+  /*
+   * For remote filters, check the time elapsed since the last fetch.
+   *
+   * Note that timestamps are signed; calculating (update time - last update)
+   * can overflow. Instead find the point in time after which a filter should
+   * have been last updated to be considered "recent enough" (that is, current
+   * time minus the update frequency). Then a filter needs an update if its
+   * last update was before that moment. Also check that the "recent enough"
+   * time point can be calculated without undeflowing beforehand.
+   */
+  return (self->manager->update_time < ADBLOCK_FILTER_UPDATE_FREQUENCY) ||
+         (self->last_update <= (self->manager->update_time - ADBLOCK_FILTER_UPDATE_FREQUENCY));
 }
 
 static void


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