protecting from invalid json syntax crashes
This commit is contained in:
parent
5d5f9be9ab
commit
8f62b45d1d
@ -60,6 +60,9 @@ char *get_string_from_json(struct json_object *json, char *string)
|
|||||||
char *get_string_from_json_string(char *json, char *string)
|
char *get_string_from_json_string(char *json, char *string)
|
||||||
{
|
{
|
||||||
struct json_object *json_obj = json_tokener_parse(json);
|
struct json_object *json_obj = json_tokener_parse(json);
|
||||||
|
|
||||||
|
if (json_obj == NULL) return NULL; //INVALID SYNTAX WAS SENT BY SOME FUCKING SCRIPT KIDDIE
|
||||||
|
|
||||||
char *returning = get_string_from_json(json_obj, string);
|
char *returning = get_string_from_json(json_obj, string);
|
||||||
|
|
||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
@ -420,7 +423,7 @@ void *why2_communicate_thread(void *arg)
|
|||||||
|
|
||||||
decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE
|
decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE
|
||||||
|
|
||||||
invalid_username = (strlen(decoded_buffer) > WHY2_MAX_USERNAME_LENGTH) || (strlen(decoded_buffer) < WHY2_MIN_USERNAME_LENGTH) || (!check_username(decoded_buffer)); //CHECK FOR USERNAMES LONGER THAN 20 CHARACTERS
|
invalid_username = decoded_buffer == NULL || (strlen(decoded_buffer) > WHY2_MAX_USERNAME_LENGTH) || (strlen(decoded_buffer) < WHY2_MIN_USERNAME_LENGTH) || (!check_username(decoded_buffer)); //CHECK FOR USERNAMES LONGER THAN 20 CHARACTERS
|
||||||
|
|
||||||
why2_deallocate(username);
|
why2_deallocate(username);
|
||||||
username = decoded_buffer;
|
username = decoded_buffer;
|
||||||
@ -571,11 +574,11 @@ char *why2_read_socket(int socket)
|
|||||||
{
|
{
|
||||||
char *raw_socket = read_socket_raw(socket);
|
char *raw_socket = read_socket_raw(socket);
|
||||||
|
|
||||||
if (raw_socket == NULL) return NULL;
|
|
||||||
|
|
||||||
char *final_message;
|
char *final_message;
|
||||||
struct json_object *json_obj = json_tokener_parse(raw_socket);
|
struct json_object *json_obj = json_tokener_parse(raw_socket);
|
||||||
|
|
||||||
|
if (raw_socket == NULL || json_obj == NULL) return NULL;
|
||||||
|
|
||||||
//GET STRINGS
|
//GET STRINGS
|
||||||
char *message = get_string_from_json(json_obj, "message");
|
char *message = get_string_from_json(json_obj, "message");
|
||||||
char *username = get_string_from_json(json_obj, "username");
|
char *username = get_string_from_json(json_obj, "username");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user