Don't decref json values in stratum parsing due to memory corruption.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
diff --git a/util.c b/util.c
index 94c4abf..5060720 100644
--- a/util.c
+++ b/util.c
@@ -1606,17 +1606,17 @@ bool parse_method(struct pool *pool, char *s)
char *buf;
if (!s)
- goto out;
+ return ret;
val = JSON_LOADS(s, &err);
if (!val) {
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
- goto out;
+ return ret;
}
method = json_object_get(val, "method");
if (!method)
- goto out;
+ return ret;
err_val = json_object_get(val, "error");
params = json_object_get(val, "params");
@@ -1632,44 +1632,40 @@ bool parse_method(struct pool *pool, char *s)
free(ss);
- goto out;
+ return ret;
}
buf = (char *)json_string_value(method);
if (!buf)
- goto out;
+ return ret;
if (!strncasecmp(buf, "mining.notify", 13)) {
if (parse_notify(pool, params))
pool->stratum_notify = ret = true;
else
pool->stratum_notify = ret = false;
- goto out;
+ return ret;
}
if (!strncasecmp(buf, "mining.set_difficulty", 21) && parse_diff(pool, params)) {
ret = true;
- goto out;
+ return ret;
}
if (!strncasecmp(buf, "client.reconnect", 16) && parse_reconnect(pool, params)) {
ret = true;
- goto out;
+ return ret;
}
if (!strncasecmp(buf, "client.get_version", 18) && send_version(pool, val)) {
ret = true;
- goto out;
+ return ret;
}
if (!strncasecmp(buf, "client.show_message", 19) && show_message(pool, params)) {
ret = true;
- goto out;
+ return ret;
}
-out:
- if (val)
- json_decref(val);
-
return ret;
}
@@ -1684,13 +1680,13 @@ bool auth_stratum(struct pool *pool)
swork_id++, pool->rpc_user, pool->rpc_pass);
if (!stratum_send(pool, s, strlen(s)))
- goto out;
+ return ret;
/* Parse all data in the queue and anything left should be auth */
while (42) {
sret = recv_line(pool);
if (!sret)
- goto out;
+ return ret;
if (parse_method(pool, sret))
free(sret);
else
@@ -1712,17 +1708,13 @@ bool auth_stratum(struct pool *pool)
applog(LOG_WARNING, "pool %d JSON stratum auth failed: %s", pool->pool_no, ss);
free(ss);
- goto out;
+ return ret;
}
ret = true;
applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
pool->probed = true;
successful_connect = true;
-out:
- if (val)
- json_decref(val);
-
return ret;
}
@@ -1935,9 +1927,6 @@ resend:
ret = true;
out:
- if (val)
- json_decref(val);
-
if (ret) {
if (!pool->stratum_url)
pool->stratum_url = pool->sockaddr_url;