Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix %c and %s format #1113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
newarg = curarg;

switch(c[1]) {
case 's':
arg = va_arg(ap,char*);
size = strlen(arg);
if (size > 0)
newarg = sdscatlen(curarg,arg,size);
break;
// case 's':
// arg = va_arg(ap,char*);
// size = strlen(arg);
// if (size > 0)
// newarg = sdscatlen(curarg,arg,size);
// break;
case 'b':
arg = va_arg(ap,char*);
size = va_arg(ap,size_t);
Expand All @@ -392,12 +392,12 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
while (*_p != '\0' && strchr(flags,*_p) != NULL) _p++;

/* Field width */
while (*_p != '\0' && isdigit(*_p)) _p++;
while (*_p != '\0' && (isdigit(*_p) || *_p == '*')) _p++;

/* Precision */
if (*_p == '.') {
_p++;
while (*_p != '\0' && isdigit(*_p)) _p++;
while (*_p != '\0' && (isdigit(*_p) || *_p == '*')) _p++;
}

/* Copy va_list before consuming with va_arg */
Expand All @@ -408,6 +408,18 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
* va_copy() to avoid UB in fmt_invalid's call to va_end(). */
if (*_p == '\0') goto fmt_invalid;

/* Char conversion (without modifiers) */
if (strchr("c",*_p) != NULL) {
va_arg(ap,int);
goto fmt_check_flag;
}

/* String conversion (without modifiers) */
if (strchr("s",*_p) != NULL) {
va_arg(ap,char*);
goto fmt_check_flag;
}

/* Integer conversion (without modifiers) */
if (strchr(intfmts,*_p) != NULL) {
va_arg(ap,int);
Expand Down Expand Up @@ -459,6 +471,12 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
}
goto fmt_invalid;
}

fmt_check_flag:
if (strchr(flags,c[1]) == NULL)
goto fmt_valid;
else
goto fmt_invalid;

fmt_invalid:
va_end(_cpy);
Expand Down