From ad75ab49d542de7e242e42da78c52ac74e916d5a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 6 Aug 2014 23:42:12 +1000 Subject: [PATCH 1/2] Avoid userpass deref --- src/generator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generator.c b/src/generator.c index b0fc61c5..312545c0 100644 --- a/src/generator.c +++ b/src/generator.c @@ -155,8 +155,8 @@ retry: /* Test we can connect, authorise and get a block template */ gbt = si->data; if (!gen_gbtbase(cs, gbt)) { - LOGINFO("Failed to get test block template from %s:%s auth %s !", - cs->url, cs->port, userpass); + LOGINFO("Failed to get test block template from %s:%s!", + cs->url, cs->port); continue; } clear_gbtbase(gbt); From a40bbda19bf55fe6e63fbece2c163cdeeef07567 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 7 Aug 2014 00:05:35 +1000 Subject: [PATCH 2/2] Don't leak memory on server reconnect --- src/generator.c | 23 +++++++++++++---------- src/libckpool.c | 1 - 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/generator.c b/src/generator.c index 312545c0..7a96e095 100644 --- a/src/generator.c +++ b/src/generator.c @@ -181,10 +181,18 @@ out: static void kill_server(server_instance_t *si) { + connsock_t *cs; + if (!si) return; - close(si->cs.fd); - si->cs.fd = -1; + cs = &si->cs; + close(cs->fd); + cs->fd = -1; + dealloc(cs->url); + dealloc(cs->port); + dealloc(cs->auth); + dealloc(si->data); + dealloc(si); } static int gen_loop(proc_instance_t *pi) @@ -1304,14 +1312,9 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) ret = gen_loop(pi); - for (i = 0; i < ckp->btcds; si = ckp->servers[i], i++) { - connsock_t *cs = &si->cs; - - dealloc(cs->url); - dealloc(cs->port); - dealloc(cs->auth); - dealloc(si->data); - dealloc(si); + for (i = 0; i < ckp->btcds; i++) { + si = ckp->servers[i]; + kill_server(si); } dealloc(ckp->servers); return ret; diff --git a/src/libckpool.c b/src/libckpool.c index fbc8e91c..f9035f6f 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -270,7 +270,6 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port) LOGWARNING("Null length url string passed to extract_sockaddr"); return false; } - *sockaddr_url = url; url_begin = strstr(url, "//"); if (!url_begin) url_begin = url;