Browse Source

Add sanity checking for values sent to srecv_process.

master
Con Kolivas 8 years ago
parent
commit
e9bf9e5a80
  1. 17
      src/stratifier.c
  2. 3
      src/stratifier.h

17
src/stratifier.c

@ -4557,7 +4557,8 @@ retry:
json_t *val = json_loads(buf, JSON_DISABLE_EOF_CHECK, NULL); json_t *val = json_loads(buf, JSON_DISABLE_EOF_CHECK, NULL);
/* This is a message for a node */ /* This is a message for a node */
ckmsgq_add(sdata->srecvs, val); if (likely(val))
ckmsgq_add(sdata->srecvs, val);
goto retry; goto retry;
} }
if (cmdmatch(buf, "ping")) { if (cmdmatch(buf, "ping")) {
@ -7431,6 +7432,11 @@ static void srecv_process(ckpool_t *ckp, json_t *val)
smsg_t *msg; smsg_t *msg;
int server; int server;
if (unlikely(!val)) {
LOGWARNING("srecv_process received NULL val!");
return;
}
msg = ckzalloc(sizeof(smsg_t)); msg = ckzalloc(sizeof(smsg_t));
msg->json_msg = val; msg->json_msg = val;
val = json_object_get(msg->json_msg, "client_id"); val = json_object_get(msg->json_msg, "client_id");
@ -7500,10 +7506,15 @@ out:
free(buf); free(buf);
} }
void stratifier_add_recv(ckpool_t *ckp, json_t *val) void _stratifier_add_recv(ckpool_t *ckp, json_t *val, const char *file, const char *func, const int line)
{ {
sdata_t *sdata = ckp->sdata; sdata_t *sdata;
if (unlikely(!val)) {
LOGWARNING("_stratifier_add_recv received NULL val from %s %s:%d", file, func, line);
return;
}
sdata = ckp->sdata;
ckmsgq_add(sdata->srecvs, val); ckmsgq_add(sdata->srecvs, val);
} }

3
src/stratifier.h

@ -17,7 +17,8 @@ void parse_upstream_workinfo(ckpool_t *ckp, json_t *val);
void parse_upstream_block(ckpool_t *ckp, json_t *val); void parse_upstream_block(ckpool_t *ckp, json_t *val);
void parse_upstream_reqtxns(ckpool_t *ckp, json_t *val); void parse_upstream_reqtxns(ckpool_t *ckp, json_t *val);
char *stratifier_stats(ckpool_t *ckp, void *data); char *stratifier_stats(ckpool_t *ckp, void *data);
void stratifier_add_recv(ckpool_t *ckp, json_t *val); void _stratifier_add_recv(ckpool_t *ckp, json_t *val, const char *file, const char *func, const int line);
#define stratifier_add_recv(ckp, val) _stratifier_add_recv(ckp, val, __FILE__, __func__, __LINE__)
void *stratifier(void *arg); void *stratifier(void *arg);
#endif /* STRATIFIER_H */ #endif /* STRATIFIER_H */

Loading…
Cancel
Save