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);