Browse Source

Fix inappropriate json object stealing

master
Con Kolivas 11 years ago
parent
commit
19c31ad0c3
  1. 10
      src/generator.c
  2. 5
      src/libckpool.c
  3. 1
      src/libckpool.h
  4. 4
      src/stratifier.c

10
src/generator.c

@ -611,7 +611,7 @@ static bool parse_diff(proxy_instance_t *proxi, json_t *val)
static bool send_version(proxy_instance_t *proxi, json_t *val) static bool send_version(proxy_instance_t *proxi, json_t *val)
{ {
json_t *json_msg, *id_val = json_object_get(val, "id"); json_t *json_msg, *id_val = json_object_dup(val, "id");
connsock_t *cs = proxi->cs; connsock_t *cs = proxi->cs;
bool ret; bool ret;
@ -1070,10 +1070,10 @@ static void *proxy_send(void *arg)
if (jobid) { if (jobid) {
val = json_pack("{s[ssooo]soss}", "params", proxi->auth, jobid, val = json_pack("{s[ssooo]soss}", "params", proxi->auth, jobid,
json_object_get(msg->json_msg, "nonce2"), json_object_dup(msg->json_msg, "nonce2"),
json_object_get(msg->json_msg, "ntime"), json_object_dup(msg->json_msg, "ntime"),
json_object_get(msg->json_msg, "nonce"), json_object_dup(msg->json_msg, "nonce"),
"id", json_object_get(msg->json_msg, "id"), "id", json_object_dup(msg->json_msg, "id"),
"method", "mining.submit"); "method", "mining.submit");
free(jobid); free(jobid);
ret = send_json_msg(cs, val); ret = send_json_msg(cs, val);

5
src/libckpool.c

@ -795,6 +795,11 @@ char *json_array_string(json_t *val, unsigned int entry)
return NULL; return NULL;
} }
json_t *json_object_dup(json_t *val, const char *entry)
{
return json_copy(json_object_get(val, entry));
}
/* Align a size_t to 4 byte boundaries for fussy arches */ /* Align a size_t to 4 byte boundaries for fussy arches */
void align_len(size_t *len) void align_len(size_t *len)

1
src/libckpool.h

@ -357,6 +357,7 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu
const char *__json_array_string(json_t *val, unsigned int entry); const char *__json_array_string(json_t *val, unsigned int entry);
char *json_array_string(json_t *val, unsigned int entry); char *json_array_string(json_t *val, unsigned int entry);
json_t *json_object_dup(json_t *val, const char *entry);
void align_len(size_t *len); void align_len(size_t *len);
void realloc_strcat(char **ptr, const char *s); void realloc_strcat(char **ptr, const char *s);

4
src/stratifier.c

@ -567,7 +567,7 @@ static void update_notify(ckpool_t *ckp)
wb->coinb2len = strlen(wb->coinb2) / 2; wb->coinb2len = strlen(wb->coinb2) / 2;
wb->coinb2bin = ckalloc(wb->coinb2len); wb->coinb2bin = ckalloc(wb->coinb2len);
hex2bin(wb->coinb2bin, wb->coinb2, wb->coinb2len); hex2bin(wb->coinb2bin, wb->coinb2, wb->coinb2len);
wb->merkle_array = json_copy(json_object_get(val, "merklehash")); wb->merkle_array = json_object_dup(val, "merklehash");
wb->merkles = json_array_size(wb->merkle_array); wb->merkles = json_array_size(wb->merkle_array);
for (i = 0; i < wb->merkles; i++) { for (i = 0; i < wb->merkles; i++) {
strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(wb->merkle_array, i))); strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(wb->merkle_array, i)));
@ -1580,7 +1580,7 @@ out_unlock:
json_set_double(val, "sdiff", sdiff); json_set_double(val, "sdiff", sdiff);
json_set_string(val, "hash", hexhash); json_set_string(val, "hash", hexhash);
json_set_bool(val, "result", result); json_set_bool(val, "result", result);
json_object_set(val, "reject-reason", json_object_get(json_msg, "reject-reason")); json_object_set(val, "reject-reason", json_object_dup(json_msg, "reject-reason"));
json_object_set(val, "error", *err_val); json_object_set(val, "error", *err_val);
s = json_dumps(val, 0); s = json_dumps(val, 0);
len = strlen(s); len = strlen(s);

Loading…
Cancel
Save