Browse Source

gossip: Avoid integer count overflow in gossip_store

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
71ec8193b2
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 6
      gossipd/gossip_store.c

6
gossipd/gossip_store.c

@ -16,7 +16,6 @@
#define GOSSIP_STORE_FILENAME "gossip_store" #define GOSSIP_STORE_FILENAME "gossip_store"
#define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp" #define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp"
#define MAX_COUNT_TO_STALE_RATE 10
static u8 gossip_store_version = 0x02; static u8 gossip_store_version = 0x02;
struct gossip_store { struct gossip_store {
@ -219,8 +218,6 @@ disable:
void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg) void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
{ {
size_t stale;
/* Only give error message once. */ /* Only give error message once. */
if (gs->fd == -1) if (gs->fd == -1)
return; return;
@ -232,8 +229,7 @@ void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
} }
gs->count++; gs->count++;
stale = gs->count - gs->broadcast->count; if (gs->count >= 1000 && gs->count > gs->broadcast->count * 1.25 &&
if (gs->count >= 100 && stale * MAX_COUNT_TO_STALE_RATE > gs->count &&
!gs->disable_compaction) !gs->disable_compaction)
gossip_store_compact(gs); gossip_store_compact(gs);
} }

Loading…
Cancel
Save