summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2018-06-26 14:33:20 +0200
committerGitHub <noreply@github.com>2018-06-26 14:33:20 +0200
commitaa5eaad48c00d541336b7e0e81605a4a7370f32c (patch)
treea5e5ac67b1ec17fbb9dfa3c2eafffbd2ae9dc0e9
parent3cf8dd2c84daf2f4ad1c1777f36b61a5f846a9c6 (diff)
parent45731edc4b215431716ec904f62a7d4d212b9d4b (diff)
downloadredis-aa5eaad48c00d541336b7e0e81605a4a7370f32c.tar.gz
Merge pull request #5037 from madolson/repl-auth-fix
Fixed replication authentication with whitespace password
-rw-r--r--src/replication.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/replication.c b/src/replication.c
index 0b7d57910..2091476d6 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)