diff --git a/src/networking.c b/src/networking.c index 8b741a0b6fa3d5b40dea3dedc47708847cfe22f0..a741718fdef87121eb4d88fe69d5c6371594828e 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 a79ec025f2ecf9cf09e728e6737cf805eb3a8129..204740cdf9754b3f7fd796f4d12d09c23ad75d6b 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 d532e385913375e8edc497bcc73aec7a1e904fe0..40d0d39ab8239c748ecad8f8cb5223bd4af9266f 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);