diff options
author | David Barksdale <amatus@amat.us> | 2017-02-20 13:08:08 -0600 |
---|---|---|
committer | David Barksdale <amatus@amat.us> | 2017-02-20 13:11:19 -0600 |
commit | fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a (patch) | |
tree | cbcbc99a93ec8f466426190a340cc46f54d2641e | |
parent | f553963d649374a75cc5a6e57df39d83565eb913 (diff) | |
download | gnunet-fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a.tar.gz gnunet-fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a.zip |
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.
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 2 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 11 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 9 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 14 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 12 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 6 | ||||
-rw-r--r-- | 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, | |||
889 | expiration.abs_value_us)) | 889 | expiration.abs_value_us)) |
890 | plugin->api->update (plugin->api->cls, | 890 | plugin->api->update (plugin->api->cls, |
891 | uid, | 891 | uid, |
892 | (int32_t) ntohl (dm->priority), | 892 | ntohl (dm->priority), |
893 | GNUNET_TIME_absolute_ntoh (dm->expiration), | 893 | GNUNET_TIME_absolute_ntoh (dm->expiration), |
894 | &check_present_continuation, | 894 | &check_present_continuation, |
895 | pc->client); | 895 | 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, | |||
611 | * @param cls our `struct Plugin *` | 611 | * @param cls our `struct Plugin *` |
612 | * @param uid unique identifier of the datum | 612 | * @param uid unique identifier of the datum |
613 | * @param delta by how much should the priority | 613 | * @param delta by how much should the priority |
614 | * change? If priority + delta < 0 the | 614 | * change? |
615 | * priority should be set to 0 (never go | ||
616 | * negative). | ||
617 | * @param expire new expiration time should be the | 615 | * @param expire new expiration time should be the |
618 | * MAX of any existing expiration time and | 616 | * MAX of any existing expiration time and |
619 | * this value | 617 | * this value |
@@ -623,7 +621,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
623 | static void | 621 | static void |
624 | heap_plugin_update (void *cls, | 622 | heap_plugin_update (void *cls, |
625 | uint64_t uid, | 623 | uint64_t uid, |
626 | int delta, | 624 | uint32_t delta, |
627 | struct GNUNET_TIME_Absolute expire, | 625 | struct GNUNET_TIME_Absolute expire, |
628 | PluginUpdateCont cont, | 626 | PluginUpdateCont cont, |
629 | void *cont_cls) | 627 | void *cont_cls) |
@@ -638,8 +636,9 @@ heap_plugin_update (void *cls, | |||
638 | GNUNET_CONTAINER_heap_update_cost (value->expire_heap, | 636 | GNUNET_CONTAINER_heap_update_cost (value->expire_heap, |
639 | expire.abs_value_us); | 637 | expire.abs_value_us); |
640 | } | 638 | } |
641 | if ( (delta < 0) && (value->priority < - delta) ) | 639 | /* Saturating add, don't overflow */ |
642 | value->priority = 0; | 640 | if (value->priority > UINT32_MAX - delta) |
641 | value->priority = UINT32_MAX; | ||
643 | else | 642 | else |
644 | value->priority += delta; | 643 | value->priority += delta; |
645 | cont (cont_cls, GNUNET_OK, NULL); | 644 | 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, | |||
395 | * @param cls our "struct Plugin*" | 395 | * @param cls our "struct Plugin*" |
396 | * @param uid unique identifier of the datum | 396 | * @param uid unique identifier of the datum |
397 | * @param delta by how much should the priority | 397 | * @param delta by how much should the priority |
398 | * change? If priority + delta < 0 the | 398 | * change? |
399 | * priority should be set to 0 (never go | ||
400 | * negative). | ||
401 | * @param expire new expiration time should be the | 399 | * @param expire new expiration time should be the |
402 | * MAX of any existing expiration time and | 400 | * MAX of any existing expiration time and |
403 | * this value | 401 | * this value |
@@ -407,13 +405,12 @@ mysql_plugin_put (void *cls, | |||
407 | static void | 405 | static void |
408 | mysql_plugin_update (void *cls, | 406 | mysql_plugin_update (void *cls, |
409 | uint64_t uid, | 407 | uint64_t uid, |
410 | int delta, | 408 | uint32_t delta, |
411 | struct GNUNET_TIME_Absolute expire, | 409 | struct GNUNET_TIME_Absolute expire, |
412 | PluginUpdateCont cont, | 410 | PluginUpdateCont cont, |
413 | void *cont_cls) | 411 | void *cont_cls) |
414 | { | 412 | { |
415 | struct Plugin *plugin = cls; | 413 | struct Plugin *plugin = cls; |
416 | uint32_t idelta = (uint32_t) delta; | ||
417 | uint64_t lexpire = expire.abs_value_us; | 414 | uint64_t lexpire = expire.abs_value_us; |
418 | int ret; | 415 | int ret; |
419 | 416 | ||
@@ -424,7 +421,7 @@ mysql_plugin_update (void *cls, | |||
424 | GNUNET_STRINGS_absolute_time_to_string (expire)); | 421 | GNUNET_STRINGS_absolute_time_to_string (expire)); |
425 | 422 | ||
426 | struct GNUNET_MY_QueryParam params_update[] = { | 423 | struct GNUNET_MY_QueryParam params_update[] = { |
427 | GNUNET_MY_query_param_uint32 (&idelta), | 424 | GNUNET_MY_query_param_uint32 (&delta), |
428 | GNUNET_MY_query_param_uint64 (&lexpire), | 425 | GNUNET_MY_query_param_uint64 (&lexpire), |
429 | GNUNET_MY_query_param_uint64 (&lexpire), | 426 | GNUNET_MY_query_param_uint64 (&lexpire), |
430 | GNUNET_MY_query_param_uint64 (&uid), | 427 | 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) | |||
76 | if (NULL == plugin->dbh) | 76 | if (NULL == plugin->dbh) |
77 | return GNUNET_SYSERR; | 77 | return GNUNET_SYSERR; |
78 | 78 | ||
79 | /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the type column because | ||
80 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel | ||
81 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. | ||
82 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. | ||
83 | */ | ||
79 | ret = | 84 | ret = |
80 | PQexec (plugin->dbh, | 85 | PQexec (plugin->dbh, |
81 | "CREATE TABLE IF NOT EXISTS gn090 (" | 86 | "CREATE TABLE IF NOT EXISTS gn090 (" |
@@ -869,9 +874,7 @@ postgres_plugin_get_expiration (void *cls, | |||
869 | * @param cls our `struct Plugin *` | 874 | * @param cls our `struct Plugin *` |
870 | * @param uid unique identifier of the datum | 875 | * @param uid unique identifier of the datum |
871 | * @param delta by how much should the priority | 876 | * @param delta by how much should the priority |
872 | * change? If priority + delta < 0 the | 877 | * change? |
873 | * priority should be set to 0 (never go | ||
874 | * negative). | ||
875 | * @param expire new expiration time should be the | 878 | * @param expire new expiration time should be the |
876 | * MAX of any existing expiration time and | 879 | * MAX of any existing expiration time and |
877 | * this value | 880 | * this value |
@@ -881,16 +884,15 @@ postgres_plugin_get_expiration (void *cls, | |||
881 | static void | 884 | static void |
882 | postgres_plugin_update (void *cls, | 885 | postgres_plugin_update (void *cls, |
883 | uint64_t uid, | 886 | uint64_t uid, |
884 | int delta, | 887 | uint32_t delta, |
885 | struct GNUNET_TIME_Absolute expire, | 888 | struct GNUNET_TIME_Absolute expire, |
886 | PluginUpdateCont cont, | 889 | PluginUpdateCont cont, |
887 | void *cont_cls) | 890 | void *cont_cls) |
888 | { | 891 | { |
889 | struct Plugin *plugin = cls; | 892 | struct Plugin *plugin = cls; |
890 | uint32_t idelta = delta; | ||
891 | uint32_t oid = (uint32_t) uid; | 893 | uint32_t oid = (uint32_t) uid; |
892 | struct GNUNET_PQ_QueryParam params[] = { | 894 | struct GNUNET_PQ_QueryParam params[] = { |
893 | GNUNET_PQ_query_param_uint32 (&idelta), | 895 | GNUNET_PQ_query_param_uint32 (&delta), |
894 | GNUNET_PQ_query_param_absolute_time (&expire), | 896 | GNUNET_PQ_query_param_absolute_time (&expire), |
895 | GNUNET_PQ_query_param_uint32 (&oid), | 897 | GNUNET_PQ_query_param_uint32 (&oid), |
896 | GNUNET_PQ_query_param_end | 898 | 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, | |||
291 | sq_prepare (plugin->dbh, | 291 | sq_prepare (plugin->dbh, |
292 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", | 292 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", |
293 | &stmt)); | 293 | &stmt)); |
294 | |||
295 | /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because | ||
296 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel | ||
297 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. | ||
298 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. | ||
299 | */ | ||
294 | if ((sqlite3_step (stmt) == SQLITE_DONE) && | 300 | if ((sqlite3_step (stmt) == SQLITE_DONE) && |
295 | (sqlite3_exec | 301 | (sqlite3_exec |
296 | (plugin->dbh, | 302 | (plugin->dbh, |
@@ -593,9 +599,7 @@ sqlite_plugin_put (void *cls, | |||
593 | * @param cls the plugin context (state for this module) | 599 | * @param cls the plugin context (state for this module) |
594 | * @param uid unique identifier of the datum | 600 | * @param uid unique identifier of the datum |
595 | * @param delta by how much should the priority | 601 | * @param delta by how much should the priority |
596 | * change? If priority + delta < 0 the | 602 | * change? |
597 | * priority should be set to 0 (never go | ||
598 | * negative). | ||
599 | * @param expire new expiration time should be the | 603 | * @param expire new expiration time should be the |
600 | * MAX of any existing expiration time and | 604 | * MAX of any existing expiration time and |
601 | * this value | 605 | * this value |
@@ -605,7 +609,7 @@ sqlite_plugin_put (void *cls, | |||
605 | static void | 609 | static void |
606 | sqlite_plugin_update (void *cls, | 610 | sqlite_plugin_update (void *cls, |
607 | uint64_t uid, | 611 | uint64_t uid, |
608 | int delta, | 612 | uint32_t delta, |
609 | struct GNUNET_TIME_Absolute expire, | 613 | struct GNUNET_TIME_Absolute expire, |
610 | PluginUpdateCont cont, | 614 | PluginUpdateCont cont, |
611 | void *cont_cls) | 615 | 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, | |||
164 | * @param cls our "struct Plugin*" | 164 | * @param cls our "struct Plugin*" |
165 | * @param uid unique identifier of the datum | 165 | * @param uid unique identifier of the datum |
166 | * @param delta by how much should the priority | 166 | * @param delta by how much should the priority |
167 | * change? If priority + delta < 0 the | 167 | * change? |
168 | * priority should be set to 0 (never go | ||
169 | * negative). | ||
170 | * @param expire new expiration time should be the | 168 | * @param expire new expiration time should be the |
171 | * MAX of any existing expiration time and | 169 | * MAX of any existing expiration time and |
172 | * this value | 170 | * this value |
@@ -174,7 +172,7 @@ template_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
174 | * @param cons_cls continuation closure | 172 | * @param cons_cls continuation closure |
175 | */ | 173 | */ |
176 | static void | 174 | static void |
177 | template_plugin_update (void *cls, uint64_t uid, int delta, | 175 | template_plugin_update (void *cls, uint64_t uid, uint32_t delta, |
178 | struct GNUNET_TIME_Absolute expire, | 176 | struct GNUNET_TIME_Absolute expire, |
179 | PluginUpdateCont cont, void *cont_cls) | 177 | PluginUpdateCont cont, void *cont_cls) |
180 | { | 178 | { |
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 | |||
268 | * @param cls closure | 268 | * @param cls closure |
269 | * @param uid unique identifier of the datum | 269 | * @param uid unique identifier of the datum |
270 | * @param delta by how much should the priority | 270 | * @param delta by how much should the priority |
271 | * change? If priority + delta < 0 the | 271 | * change? |
272 | * priority should be set to 0 (never go | ||
273 | * negative). | ||
274 | * @param expire new expiration time should be the | 272 | * @param expire new expiration time should be the |
275 | * MAX of any existing expiration time and | 273 | * MAX of any existing expiration time and |
276 | * this value | 274 | * this value |
@@ -280,7 +278,7 @@ typedef void | |||
280 | typedef void | 278 | typedef void |
281 | (*PluginUpdate) (void *cls, | 279 | (*PluginUpdate) (void *cls, |
282 | uint64_t uid, | 280 | uint64_t uid, |
283 | int delta, | 281 | uint32_t delta, |
284 | struct GNUNET_TIME_Absolute expire, | 282 | struct GNUNET_TIME_Absolute expire, |
285 | PluginUpdateCont cont, | 283 | PluginUpdateCont cont, |
286 | void *cont_cls); | 284 | void *cont_cls); |