aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_heap.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amat.us>2017-02-20 13:08:08 -0600
committerDavid Barksdale <amatus@amat.us>2017-02-20 13:11:19 -0600
commitfe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a (patch)
treecbcbc99a93ec8f466426190a340cc46f54d2641e /src/datastore/plugin_datastore_heap.c
parentf553963d649374a75cc5a6e57df39d83565eb913 (diff)
downloadgnunet-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.
Diffstat (limited to 'src/datastore/plugin_datastore_heap.c')
-rw-r--r--src/datastore/plugin_datastore_heap.c11
1 files changed, 5 insertions, 6 deletions
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,
623static void 621static void
624heap_plugin_update (void *cls, 622heap_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);