From 5633f8365df0082920d99ff669d0ca2a2c91812a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 24 Apr 2015 21:17:24 +1000 Subject: [PATCH] Prevent theoretical read out of bounds --- src/stratifier.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index 1b50a2cb..00c9b000 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1348,7 +1348,7 @@ static stratum_instance_t *__recruit_stratum_instance(sdata_t *sdata) /* Enter with write instance_lock held */ static stratum_instance_t *__stratum_add_instance(ckpool_t *ckp, const int64_t id, - const char *address, const int server) + const char *address, int server) { stratum_instance_t *client; sdata_t *sdata = ckp->data; @@ -1357,6 +1357,9 @@ static stratum_instance_t *__stratum_add_instance(ckpool_t *ckp, const int64_t i client->id = id; client->session_id = ++sdata->session_id; strcpy(client->address, address); + /* Sanity check to not overflow lookup in ckp->serverurl[] */ + if (server >= ckp->serverurls) + server = 0; client->server = server; client->diff = client->old_diff = ckp->startdiff; client->ckp = ckp;