summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-07-03 11:59:44 +0200
committerantirez <antirez@gmail.com>2013-07-03 11:59:44 +0200
commitfbb97c6b13308df876f277117b74b58f4a717e4f (patch)
treebdc0a0c58b4e44fb83cda7cc74bcda560a169235
parent7e63167d27d8dc9ceb96bd595e010115285c4b89 (diff)
downloadredis-fbb97c6b13308df876f277117b74b58f4a717e4f.tar.gz
redis-cli --pipe: send final ECHO in a safer way.
If the protocol read from stdin happened to contain grabage (invalid random chars), in the previous implementation it was possible to end with something like: dksfjdksjflskfjl*2\r\n$4\r\nECHO.... That is invalid as the *2 should start into a new line. Now we prefix the ECHO with a CRLF that has no effects on the server but prevents this issues most of the times. Of course if the offending wrong sequence is something like: $3248772349\r\n No one is going to save us as Redis will wait for data in the context of a big argument, so this fix does not cover all the cases. This partially fixes issue #681.
-rw-r--r--src/redis-cli.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 5914fd2c4..8cf1c4646 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -1204,8 +1204,12 @@ static void pipeMode(void) {
ssize_t nread = read(STDIN_FILENO,obuf,sizeof(obuf));
if (nread == 0) {
+ /* The ECHO sequence starts with a "\r\n" so that if there
+ * is garbage in the protocol we read from stdin, the ECHO
+ * will likely still be properly formatted.
+ * CRLF is ignored by Redis, so it has no effects. */
char echo[] =
- "*2\r\n$4\r\nECHO\r\n$20\r\n01234567890123456789\r\n";
+ "\r\n*2\r\n$4\r\nECHO\r\n$20\r\n01234567890123456789\r\n";
int j;
eof = 1;
@@ -1214,7 +1218,7 @@ static void pipeMode(void) {
* to make sure everything was read from the server. */
for (j = 0; j < 20; j++)
magic[j] = rand() & 0xff;
- memcpy(echo+19,magic,20);
+ memcpy(echo+21,magic,20);
memcpy(obuf,echo,sizeof(echo)-1);
obuf_len = sizeof(echo)-1;
obuf_pos = 0;