From 9b0bb4e80e5df62e383d2f04a0ae7cea0d659790 Mon Sep 17 00:00:00 2001 From: Andrew Beekhof Date: Thu, 7 Jun 2012 14:40:34 +1000 Subject: [PATCH] LOG: Observe field widths when serializing string arguments --- lib/log_format.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/log_format.c b/lib/log_format.c index 4a51d58..ca98fcc 100644 --- a/lib/log_format.c +++ b/lib/log_format.c @@ -386,6 +386,7 @@ qb_vsprintf_serialize(char *serialize, const char *fmt, va_list ap) uint32_t location = 0; int type_long = 0; int type_longlong = 0; + int sformat_length = 0; p = stpcpy(serialize, fmt); location = p - serialize + 1; @@ -408,6 +409,8 @@ reprocess: case '\'': /* group in thousands, ignore */ case 'I': /* glibc-ism locale alternative, ignore */ case '.': /* precision, ignore */ + format++; + goto reprocess; case '0': /* field width, ignore */ case '1': /* field width, ignore */ case '2': /* field width, ignore */ @@ -418,6 +421,8 @@ reprocess: case '7': /* field width, ignore */ case '8': /* field width, ignore */ case '9': /* field width, ignore */ + sformat_length *= 10; + sformat_length += (format[0] - '0'); format++; goto reprocess; @@ -505,6 +510,9 @@ reprocess: arg_string = va_arg(ap, char *); if (arg_string == NULL) { p = stpcpy(&serialize[location], "(null)"); + } else if (sformat_length) { + p = stpncpy(&serialize[location], arg_string, sformat_length); + serialize[location+sformat_length] = 0; } else { p = stpcpy(&serialize[location], arg_string); } @@ -520,6 +528,7 @@ reprocess: } case '%': serialize[location++] = '%'; + sformat_length = 0; break; }