From 7f0824260baa47819ae89223e0aeb583c10c9b82 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 25 Apr 2014 19:18:22 +1000 Subject: [PATCH] Disconnect clients that send invalid json --- src/connector.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/connector.c b/src/connector.c index 0b1f4de7..2da6450d 100644 --- a/src/connector.c +++ b/src/connector.c @@ -91,6 +91,8 @@ static void invalidate_client(client_instance_t *client) client->fd = -1; } +static void send_client(conn_instance_t *ci, int id, const char *buf); + static void parse_client_msg(conn_instance_t *ci, client_instance_t *client) { ckpool_t *ckp = ci->pi->ckp; @@ -144,9 +146,12 @@ reparse: client->bufofs -= buflen; memmove(client->buf, client->buf + buflen, client->bufofs); val = json_loads(msg, 0, NULL); - if (!val) - LOGWARNING("Client fd %d sent invalid json message %s", client->fd, msg); - else { + if (!val) { + LOGINFO("Client id %d sent invalid json message %s", client->id, msg); + send_client(ci, client->id, "Invalid JSON, disconnecting\n"); + invalidate_client(client); + return; + } else { char *s; json_object_set_new_nocheck(val, "client_id", json_integer(client->id));