From becf5fdb0c2df94db46c1f838638de892a347250 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 21 Nov 2011 16:17:51 +0100 Subject: [PATCH] Close client connection and log the event when the client input buffer reaches 1GB. --- src/networking.c | 7 +++++++ src/redis.c | 1 + src/redis.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/networking.c b/src/networking.c index 8b741a0b..a741718f 100644 --- a/src/networking.c +++ b/src/networking.c @@ -903,6 +903,13 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) { } else { return; } + if (sdslen(c->querybuf) > server.client_max_querybuf_len) { + sds ci = getClientInfoString(c); + redisLog(REDIS_WARNING,"Closing client that reached max query buffer length: %s", ci); + sdsfree(ci); + freeClient(c); + return; + } processInputBuffer(c); } diff --git a/src/redis.c b/src/redis.c index a79ec025..204740cd 100644 --- a/src/redis.c +++ b/src/redis.c @@ -843,6 +843,7 @@ void initServerConfig() { server.dbnum = REDIS_DEFAULT_DBNUM; server.verbosity = REDIS_VERBOSE; server.maxidletime = REDIS_MAXIDLETIME; + server.client_max_querybuf_len = REDIS_MAX_QUERYBUF_LEN; server.saveparams = NULL; server.loading = 0; server.logfile = NULL; /* NULL = log on standard output */ diff --git a/src/redis.h b/src/redis.h index d532e385..40d0d39a 100644 --- a/src/redis.h +++ b/src/redis.h @@ -40,6 +40,7 @@ /* Static server configuration */ #define REDIS_SERVERPORT 6379 /* TCP port */ #define REDIS_MAXIDLETIME 0 /* default client timeout: infinite */ +#define REDIS_MAX_QUERYBUF_LEN (1024*1024*1024) /* 1GB max query buffer. */ #define REDIS_IOBUF_LEN (1024*16) #define REDIS_LOADBUF_LEN 1024 #define REDIS_DEFAULT_DBNUM 16 @@ -533,6 +534,7 @@ struct redisServer { /* Configuration */ int verbosity; int maxidletime; + size_t client_max_querybuf_len; int dbnum; int daemonize; int appendonly; @@ -765,6 +767,7 @@ void addReplyMultiBulkLen(redisClient *c, long length); void *dupClientReplyValue(void *o); void getClientsMaxBuffers(unsigned long *longest_output_list, unsigned long *biggest_input_buffer); +sds getClientInfoString(redisClient *client); void rewriteClientCommandVector(redisClient *c, int argc, ...); void rewriteClientCommandArgument(redisClient *c, int i, robj *newval); -- 2.45.2