Support cJSON < 1.7.13.

This commit is contained in:
Roger A. Light 2020-11-25 16:57:33 +00:00
parent 0713ad38b1
commit 69f7fcae82
2 changed files with 13 additions and 1 deletions

View File

@ -73,4 +73,9 @@
# define HAVE_PTHREAD_CANCEL # define HAVE_PTHREAD_CANCEL
#endif #endif
#ifdef WITH_CJSON
# include <cJSON.h>
# define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH)
#endif
#endif #endif

View File

@ -93,8 +93,15 @@ static int dynsec_control_callback(int event, void *event_data, void *userdata)
cJSON_AddItemToObject(j_response_tree, "responses", j_responses); 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); tree = cJSON_ParseWithLength(ed->payload, ed->payloadlen);
#endif
if(tree == NULL){ if(tree == NULL){
dynsec__command_reply(j_responses, ed->client, "Unknown command", "Payload not valid JSON", NULL); dynsec__command_reply(j_responses, ed->client, "Unknown command", "Payload not valid JSON", NULL);
send_response(j_response_tree); send_response(j_response_tree);