From 69f7fcae82d6a57439da6286f37a67c983838abc Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 25 Nov 2020 16:57:33 +0000 Subject: [PATCH] Support cJSON < 1.7.13. --- config.h | 5 +++++ plugins/dynamic-security/plugin.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index 42658599..77da39df 100644 --- a/config.h +++ b/config.h @@ -73,4 +73,9 @@ # define HAVE_PTHREAD_CANCEL #endif +#ifdef WITH_CJSON +# include +# define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH) +#endif + #endif diff --git a/plugins/dynamic-security/plugin.c b/plugins/dynamic-security/plugin.c index a95c23dc..a011c100 100644 --- a/plugins/dynamic-security/plugin.c +++ b/plugins/dynamic-security/plugin.c @@ -93,8 +93,15 @@ static int dynsec_control_callback(int event, void *event_data, void *userdata) cJSON_AddItemToObject(j_response_tree, "responses", j_responses); - /* Parse cJSON tree */ + /* Parse cJSON tree. + * Using cJSON_ParseWithLength() is the best choice here, but Mosquitto + * always adds an extra 0 to the end of the payload memory, so using + * cJSON_Parse() on its own will still not overrun. */ +#if CJSON_VERSION_FULL < 1007013 + tree = cJSON_Parse(ed->payload); +#else tree = cJSON_ParseWithLength(ed->payload, ed->payloadlen); +#endif if(tree == NULL){ dynsec__command_reply(j_responses, ed->client, "Unknown command", "Payload not valid JSON", NULL); send_response(j_response_tree);