gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] 01/02: Restrict update to positive priority deltas


From: gnunet
Subject: [GNUnet-SVN] [gnunet] 01/02: Restrict update to positive priority deltas
Date: Mon, 20 Feb 2017 20:11:46 +0100

This is an automated email from the git hooks/post-receive script.

david-barksdale pushed a commit to branch master
in repository gnunet.

commit fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a
Author: David Barksdale <address@hidden>
AuthorDate: Mon Feb 20 13:08:08 2017 -0600

    Restrict update to positive priority deltas
    
    This is only ever called with positive values and the mysql and postgres
    plugins were not handling negative values correctly anyway.
---
 src/datastore/gnunet-service-datastore.c  |  2 +-
 src/datastore/plugin_datastore_heap.c     | 11 +++++------
 src/datastore/plugin_datastore_mysql.c    |  9 +++------
 src/datastore/plugin_datastore_postgres.c | 14 ++++++++------
 src/datastore/plugin_datastore_sqlite.c   | 12 ++++++++----
 src/datastore/plugin_datastore_template.c |  6 ++----
 src/include/gnunet_datastore_plugin.h     |  6 ++----
 7 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/datastore/gnunet-service-datastore.c 
b/src/datastore/gnunet-service-datastore.c
index 6f1bd2b6d..445c3576e 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -889,7 +889,7 @@ check_present (void *cls,
          expiration.abs_value_us))
       plugin->api->update (plugin->api->cls,
                           uid,
-                           (int32_t) ntohl (dm->priority),
+                           ntohl (dm->priority),
                            GNUNET_TIME_absolute_ntoh (dm->expiration),
                            &check_present_continuation,
                           pc->client);
diff --git a/src/datastore/plugin_datastore_heap.c 
b/src/datastore/plugin_datastore_heap.c
index 977d599d2..199c03a50 100644
--- a/src/datastore/plugin_datastore_heap.c
+++ b/src/datastore/plugin_datastore_heap.c
@@ -611,9 +611,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor 
proc,
  * @param cls our `struct Plugin *`
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -623,7 +621,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor 
proc,
 static void
 heap_plugin_update (void *cls,
                    uint64_t uid,
-                   int delta,
+                   uint32_t delta,
                    struct GNUNET_TIME_Absolute expire,
                    PluginUpdateCont cont,
                    void *cont_cls)
@@ -638,8 +636,9 @@ heap_plugin_update (void *cls,
     GNUNET_CONTAINER_heap_update_cost (value->expire_heap,
                                       expire.abs_value_us);
   }
-  if ( (delta < 0) && (value->priority < - delta) )
-    value->priority = 0;
+  /* Saturating add, don't overflow */
+  if (value->priority > UINT32_MAX - delta)
+    value->priority = UINT32_MAX;
   else
     value->priority += delta;
   cont (cont_cls, GNUNET_OK, NULL);
diff --git a/src/datastore/plugin_datastore_mysql.c 
b/src/datastore/plugin_datastore_mysql.c
index d76b4ccb4..1067064aa 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -395,9 +395,7 @@ mysql_plugin_put (void *cls,
  * @param cls our "struct Plugin*"
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -407,13 +405,12 @@ mysql_plugin_put (void *cls,
 static void
 mysql_plugin_update (void *cls,
                      uint64_t uid,
-                     int delta,
+                     uint32_t delta,
                      struct GNUNET_TIME_Absolute expire,
                      PluginUpdateCont cont,
                      void *cont_cls)
 {
   struct Plugin *plugin = cls;
-  uint32_t idelta = (uint32_t) delta;
   uint64_t lexpire = expire.abs_value_us;
   int ret;
 
@@ -424,7 +421,7 @@ mysql_plugin_update (void *cls,
              GNUNET_STRINGS_absolute_time_to_string (expire));
 
   struct GNUNET_MY_QueryParam params_update[] = {
-    GNUNET_MY_query_param_uint32 (&idelta),
+    GNUNET_MY_query_param_uint32 (&delta),
     GNUNET_MY_query_param_uint64 (&lexpire),
     GNUNET_MY_query_param_uint64 (&lexpire),
     GNUNET_MY_query_param_uint64 (&uid),
diff --git a/src/datastore/plugin_datastore_postgres.c 
b/src/datastore/plugin_datastore_postgres.c
index 994118bfa..7b04cc68a 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -76,6 +76,11 @@ init_connection (struct Plugin *plugin)
   if (NULL == plugin->dbh)
     return GNUNET_SYSERR;
 
+  /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the 
type column because
+   * we only test equality on it and can cast it to/from uint32_t. For repl, 
prio, and anonLevel
+   * we do math or inequality tests, so we can't handle the entire range of 
uint32_t.
+   * This will also cause problems for expiration times after 
294247-01-10-04:00:54 UTC.
+   */
   ret =
       PQexec (plugin->dbh,
               "CREATE TABLE IF NOT EXISTS gn090 ("
@@ -869,9 +874,7 @@ postgres_plugin_get_expiration (void *cls,
  * @param cls our `struct Plugin *`
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -881,16 +884,15 @@ postgres_plugin_get_expiration (void *cls,
 static void
 postgres_plugin_update (void *cls,
                        uint64_t uid,
-                       int delta,
+                       uint32_t delta,
                         struct GNUNET_TIME_Absolute expire,
                         PluginUpdateCont cont,
                        void *cont_cls)
 {
   struct Plugin *plugin = cls;
-  uint32_t idelta = delta;
   uint32_t oid = (uint32_t) uid;
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_uint32 (&idelta),
+    GNUNET_PQ_query_param_uint32 (&delta),
     GNUNET_PQ_query_param_absolute_time (&expire),
     GNUNET_PQ_query_param_uint32 (&oid),
     GNUNET_PQ_query_param_end
diff --git a/src/datastore/plugin_datastore_sqlite.c 
b/src/datastore/plugin_datastore_sqlite.c
index 18a3aa4ac..028117d26 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -291,6 +291,12 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle 
*cfg,
          sq_prepare (plugin->dbh,
                      "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
                      &stmt));
+
+  /* FIXME: SQLite does not have unsigned integers! This is ok for the type 
column because
+   * we only test equality on it and can cast it to/from uint32_t. For repl, 
prio, and anonLevel
+   * we do math or inequality tests, so we can't handle the entire range of 
uint32_t.
+   * This will also cause problems for expiration times after 
294247-01-10-04:00:54 UTC.
+   */
   if ((sqlite3_step (stmt) == SQLITE_DONE) &&
       (sqlite3_exec
        (plugin->dbh,
@@ -593,9 +599,7 @@ sqlite_plugin_put (void *cls,
  * @param cls the plugin context (state for this module)
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -605,7 +609,7 @@ sqlite_plugin_put (void *cls,
 static void
 sqlite_plugin_update (void *cls,
                       uint64_t uid,
-                      int delta,
+                      uint32_t delta,
                       struct GNUNET_TIME_Absolute expire,
                       PluginUpdateCont cont,
                       void *cont_cls)
diff --git a/src/datastore/plugin_datastore_template.c 
b/src/datastore/plugin_datastore_template.c
index fdd4fb157..a1e03e8ee 100644
--- a/src/datastore/plugin_datastore_template.c
+++ b/src/datastore/plugin_datastore_template.c
@@ -164,9 +164,7 @@ template_plugin_get_expiration (void *cls, 
PluginDatumProcessor proc,
  * @param cls our "struct Plugin*"
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -174,7 +172,7 @@ template_plugin_get_expiration (void *cls, 
PluginDatumProcessor proc,
  * @param cons_cls continuation closure
  */
 static void
-template_plugin_update (void *cls, uint64_t uid, int delta,
+template_plugin_update (void *cls, uint64_t uid, uint32_t delta,
                         struct GNUNET_TIME_Absolute expire,
                         PluginUpdateCont cont, void *cont_cls)
 {
diff --git a/src/include/gnunet_datastore_plugin.h 
b/src/include/gnunet_datastore_plugin.h
index 71c69ffaf..2295d4e72 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -268,9 +268,7 @@ typedef void
  * @param cls closure
  * @param uid unique identifier of the datum
  * @param delta by how much should the priority
- *     change?  If priority + delta < 0 the
- *     priority should be set to 0 (never go
- *     negative).
+ *     change?
  * @param expire new expiration time should be the
  *     MAX of any existing expiration time and
  *     this value
@@ -280,7 +278,7 @@ typedef void
 typedef void
 (*PluginUpdate) (void *cls,
                 uint64_t uid,
-                int delta,
+                uint32_t delta,
                 struct GNUNET_TIME_Absolute expire,
                 PluginUpdateCont cont,
                 void *cont_cls);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]