Support cJSON < 1.7.13.
This commit is contained in:
parent
0713ad38b1
commit
69f7fcae82
5
config.h
5
config.h
@ -73,4 +73,9 @@
|
||||
# define HAVE_PTHREAD_CANCEL
|
||||
#endif
|
||||
|
||||
#ifdef WITH_CJSON
|
||||
# include <cJSON.h>
|
||||
# define CJSON_VERSION_FULL (CJSON_VERSION_MAJOR*1000000+CJSON_VERSION_MINOR*1000+CJSON_VERSION_PATCH)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user