From e8d68b6b72c7bbba63120d9024138dacd583d22d Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Tue, 19 Jun 2018 05:38:53 +0000 Subject: [PATCH 1/2] Fixed replication authentication with whitespace in password --- src/replication.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/replication.c b/src/replication.c index 0b7d57910..5b344f49e 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1315,23 +1315,30 @@ error: #define SYNC_CMD_FULL (SYNC_CMD_READ|SYNC_CMD_WRITE) char *sendSynchronousCommand(int flags, int fd, ...) { - /* Create the command to send to the master, we use simple inline - * protocol for simplicity as currently we only send simple strings. */ + /* Create the command to send to the master, we use redis binary + * protocol to make sure correct arguments are sent. This function + * is not safe for all binary data.*/ if (flags & SYNC_CMD_WRITE) { char *arg; va_list ap; sds cmd = sdsempty(); + sds cmdargs = sdsempty(); + int argslen = 0; va_start(ap,fd); while(1) { arg = va_arg(ap, char*); if (arg == NULL) break; - if (sdslen(cmd) != 0) cmd = sdscatlen(cmd," ",1); - cmd = sdscat(cmd,arg); + cmdargs = sdscatprintf(cmdargs,"$%zu\r\n%s\r\n",strlen(arg),arg); + argslen++; } - cmd = sdscatlen(cmd,"\r\n",2); + va_end(ap); + + cmd = sdscatprintf(cmd,"*%zu\r\n",argslen); + cmd = sdscatsds(cmd,cmdargs); + sdsfree(cmdargs); /* Transfer command to the server. */ if (syncWrite(fd,cmd,sdslen(cmd),server.repl_syncio_timeout*1000) From 45731edc4b215431716ec904f62a7d4d212b9d4b Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Tue, 26 Jun 2018 00:57:35 +0000 Subject: [PATCH 2/2] Addressed comments --- src/replication.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/replication.c b/src/replication.c index 5b344f49e..2091476d6 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1317,7 +1317,7 @@ char *sendSynchronousCommand(int flags, int fd, ...) { /* Create the command to send to the master, we use redis binary * protocol to make sure correct arguments are sent. This function - * is not safe for all binary data.*/ + * is not safe for all binary data. */ if (flags & SYNC_CMD_WRITE) { char *arg; va_list ap;