Skip to content

Commit

Permalink
Abort on invalid format
Browse files Browse the repository at this point in the history
There is no way we can guess the width of the argument when we cannot
infer its type from the format specifier.
  • Loading branch information
pietern committed Jul 9, 2011
1 parent 27c96dd commit 2da784c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,8 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
}

fmt_invalid:
/* Consume and discard vararg */
va_arg(ap,void);
va_end(_cpy);
break;
goto err;

fmt_valid:
_l = (_p+1)-c;
Expand Down
6 changes: 2 additions & 4 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,9 @@ static void test_format_commands(void) {
len == 4+4+(8+2)+4+(3+2));
free(cmd);

test("Format command with wrong printf format and extra interpolation: ");
test("Format command with invalid printf format: ");
len = redisFormatCommand(&cmd,"key:%08p %b",1234,"foo",3);
test_cond(strncmp(cmd,"*2\r\n$6\r\nkey:8p\r\n$3\r\nfoo\r\n",len) == 0 &&
len == 4+4+(6+2)+4+(3+2));
free(cmd);
test_cond(len == -1);

const char *argv[3];
argv[0] = "SET";
Expand Down

0 comments on commit 2da784c

Please sign in to comment.