Skip to content

Commit

Permalink
LOG: Restrict string trucation during serialization to when a precisi…
Browse files Browse the repository at this point in the history
…on is specified
  • Loading branch information
beekhof committed Jun 7, 2012
1 parent bb2e307 commit e70e790
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/log_format.c
Expand Up @@ -387,6 +387,7 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
int type_long = 0;
int type_longlong = 0;
int sformat_length = 0;
int sformat_precision = 0;

p = stpcpy(serialize, fmt);
location = p - serialize + 1;
Expand All @@ -408,8 +409,11 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
case '+': /* a sign should be used, ignore */
case '\'': /* group in thousands, ignore */
case 'I': /* glibc-ism locale alternative, ignore */
format++;
goto reprocess;
case '.': /* precision, ignore */
format++;
sformat_precision = 1;
goto reprocess;
case '0': /* field width, ignore */
case '1': /* field width, ignore */
Expand All @@ -421,11 +425,12 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
case '7': /* field width, ignore */
case '8': /* field width, ignore */
case '9': /* field width, ignore */
sformat_length *= 10;
sformat_length += (format[0] - '0');
if(sformat_precision) {
sformat_length *= 10;
sformat_length += (format[0] - '0');
}
format++;
goto reprocess;

case '*': /* variable field width, save */ {
int arg_int = va_arg(ap, int);
memcpy(&serialize[location], &arg_int, sizeof (int));
Expand Down Expand Up @@ -529,6 +534,7 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap)
case '%':
serialize[location++] = '%';
sformat_length = 0;
sformat_precision = 0;
break;

}
Expand Down

0 comments on commit e70e790

Please sign in to comment.