From 8bd3df1ae168f367694455bf7dd512144acec740 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 30 Aug 2024 13:41:01 +0200 Subject: [PATCH] added json format validation to read_socket_raw --- src/chat/misc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index 3715a4f..778aafc 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -188,7 +188,20 @@ char *read_socket_raw(int socket) return_section: - content_buffer[content_size] = '\0'; + content_buffer[content_size] = '\0'; //NULL TERM + + //VALIDATE JSON FORMAT + struct json_object *json = json_tokener_parse(content_buffer); + if (json == NULL) + { + //RESET content_buffer + why2_deallocate(content_buffer); + content_buffer = NULL; + } else + { + //DEALLOCATION + json_object_put(json); + } return content_buffer; }