Close client connection and log the event when the client input buffer reaches 1GB.

This commit is contained in:
antirez 2011-11-21 16:17:51 +01:00
parent 6621b8ffa1
commit becf5fdb0c
3 changed files with 11 additions and 0 deletions

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);