From 360a0646bb0f7373caab08382772ca0384c1fe6d Mon Sep 17 00:00:00 2001 From: Paulino Huerta Date: Sat, 14 May 2016 01:53:48 +0200 Subject: Typo format in redisFormatSdsCommandArgv function this issue is very significant, because not allow the proper execution of the "function redisCommandArgv". The server returns "invalid bulk length". Thanks! --- hiredis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hiredis.c b/hiredis.c index 2b876d9..18bdfc9 100644 --- a/hiredis.c +++ b/hiredis.c @@ -507,7 +507,7 @@ int redisFormatSdsCommandArgv(sds *target, int argc, const char **argv, cmd = sdscatfmt(cmd, "*%i\r\n", argc); for (j=0; j < argc; j++) { len = argvlen ? argvlen[j] : strlen(argv[j]); - cmd = sdscatfmt(cmd, "$%T\r\n", len); + cmd = sdscatfmt(cmd, "$%u\r\n", len); cmd = sdscatlen(cmd, argv[j], len); cmd = sdscatlen(cmd, "\r\n", sizeof("\r\n")-1); } -- cgit v1.2.3 From 8655a6ac7a1bdd9b04d669585b4ae430c167ad80 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sat, 14 May 2016 11:26:18 +0200 Subject: test: Add regression test for sds argv formatting --- test.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test.c b/test.c index 538d376..a23d606 100644 --- a/test.c +++ b/test.c @@ -224,6 +224,22 @@ static void test_format_commands(void) { test_cond(strncmp(cmd,"*3\r\n$3\r\nSET\r\n$7\r\nfoo\0xxx\r\n$3\r\nbar\r\n",len) == 0 && len == 4+4+(3+2)+4+(7+2)+4+(3+2)); free(cmd); + + sds sds_cmd; + + sds_cmd = sdsempty(); + test("Format command into sds by passing argc/argv without lengths: "); + len = redisFormatSdsCommandArgv(&sds_cmd,argc,argv,NULL); + test_cond(strncmp(sds_cmd,"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n",len) == 0 && + len == 4+4+(3+2)+4+(3+2)+4+(3+2)); + sdsfree(sds_cmd); + + sds_cmd = sdsempty(); + test("Format command into sds by passing argc/argv with lengths: "); + len = redisFormatSdsCommandArgv(&sds_cmd,argc,argv,lens); + test_cond(strncmp(sds_cmd,"*3\r\n$3\r\nSET\r\n$7\r\nfoo\0xxx\r\n$3\r\nbar\r\n",len) == 0 && + len == 4+4+(3+2)+4+(7+2)+4+(3+2)); + sdsfree(sds_cmd); } static void test_append_formatted_commands(struct config config) { -- cgit v1.2.3