From e9bf9e5a80a12db6d6a267a768b28bec8c53dfbd Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 20 Mar 2017 18:56:34 +1100 Subject: [PATCH] Add sanity checking for values sent to srecv_process. --- src/stratifier.c | 17 ++++++++++++++--- src/stratifier.h | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index f842121d..2630bd09 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -4557,7 +4557,8 @@ retry: json_t *val = json_loads(buf, JSON_DISABLE_EOF_CHECK, NULL); /* This is a message for a node */ - ckmsgq_add(sdata->srecvs, val); + if (likely(val)) + ckmsgq_add(sdata->srecvs, val); goto retry; } if (cmdmatch(buf, "ping")) { @@ -7431,6 +7432,11 @@ static void srecv_process(ckpool_t *ckp, json_t *val) smsg_t *msg; int server; + if (unlikely(!val)) { + LOGWARNING("srecv_process received NULL val!"); + return; + } + msg = ckzalloc(sizeof(smsg_t)); msg->json_msg = val; val = json_object_get(msg->json_msg, "client_id"); @@ -7500,10 +7506,15 @@ out: 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); } diff --git a/src/stratifier.h b/src/stratifier.h index 08e55597..2c4375cf 100644 --- a/src/stratifier.h +++ b/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_reqtxns(ckpool_t *ckp, json_t *val); 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); #endif /* STRATIFIER_H */